473,387 Members | 1,453 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

putting data from a methods return into an array

Hey, i have this method here that reads data into an array from a file and then returns it:

Expand|Select|Wrap|Line Numbers
  1.     public String[] getLinesOfData(String filename) {
  2.  
  3.         String dataStr = getData(filename);
  4.         String[] linesOfData = dataStr.split("\n");        
  5.         System.out.println(Arrays.toString(linesOfData))
  6.         return linesOfData;        
  7.     }    
the data is shown exactly how it should be , however i want to know how i get this data into an array in a constructor in another class as currently i have the code:

Expand|Select|Wrap|Line Numbers
  1.         SimpleFileReader filereader = new SimpleFileReader();
  2.  
  3.         dataArray = filereader.getLinesOfData(filename); 

i have defined dataArray as:

Expand|Select|Wrap|Line Numbers
  1.  String[] dataArray; 



and in a different method i print:

Expand|Select|Wrap|Line Numbers
  1. System.out.println(dataArray.length);
i get the correct length



however when i print:

Expand|Select|Wrap|Line Numbers
  1. System.out.println(Arrays.asList(dataArray));
the values that i previously printed are all shown as null, apart from the last 3 lines of the text file that the data is in. i assume it is something i am doing wrong when i attempt to put the data into the "dataArray", what is the correct way for me to do this?? thanks
Dec 15 '10 #1
1 1713
SOLVED this one, was a different problem than i first thought, very very foolish of me :)
Dec 15 '10 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

25
by: cppaddict | last post by:
I'd like to know what goes on under the hood when methods return objects. Eg, I have a simple Point class with two members _x and _y. It's constructor, copy constructor, assignment operator and...
0
by: Marc van Boven | last post by:
I'm stuck with the following problem: My nusoap-client calls a server-function giveCombination(). The function giveCombination should return something like array( => array( 'a_id' => 6,...
16
by: priya | last post by:
Hi all, I am new to this group.I am working in c language.I have dount in pointer? how to retun array of pointer in function? example main()
2
by: kathy | last post by:
how to return array from function?
2
by: Ali | last post by:
hi i need to send some data to the function and want to return array of object bac lik dim obj() as myclass=AddIt(i,j i dont know that is write syntax or no public function addit(byval i as...
1
by: becca0619 | last post by:
Hey, Ive been looking around to find out how to read data into a 2D array and I cant find a solution that will fit my assignment. Im not sure that I should even use an array actually... ok so...
1
by: Naha | last post by:
Hi Guys, this is the code that reads the data from a text file and displays it in a jsp. iam trying to put the data in a array so that each time the code readfs the data the previous data is...
10
by: Raj | last post by:
I need a VB function to return array of collections like Private Type Employee empname as string address as string salary as integer deptno as integer End Type dim employees() as Employee
3
by: luftikus143 | last post by:
Hi there, I need to store three pieces of data - a result of a SQL query - in a multidimensional array, but don't really succeed. Sometimes it works, but then the output doesn't work accordingly....
3
by: lilbit02 | last post by:
Hi, I want to grab data from a .csv file and add all the data to the array. I have the part where I'm grabbing the data from the .csv file but the array issue I haven't totally figured out. ...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.