Populate an arraylist....

G

gbattine

Hi guys,
i'm a new java user and i have a big question for you.
I'm developing a jsf application with eclipse and i have a problem.
I have to import a txt file with this format

string string string string
string double double double
string double double double
string double double double
etc....

The file is composed by a first row that has 4 columns of string type
and other rows of 4 columns with first column string and the others
double.
I have to define 2 object, a first headline object that is an array of
string, for storing the first row, and a second object that is composed
by a string field and by an array of double.

Code:
Headline string[]=new string[4];
public class row{
String geneid=null;
values double[]=null;
}
public void row(String idGene,double[3] x ) {
this.geneid=idPr;
this.values=x;
}
This code is correct?
For storing my file i need an headline array of string and an arraylist
of row objects.
How can populate them with the txt file?
I've loaded the file with
Code:
BufferedReader br = new BufferedReader(new
InputStreamReader(myFile.getInputStream()));

Can you help me with some code?I'm not expert....
 
H

Henry

gbattine said:
Hi guys,
i'm a new java user and i have a big question for you.
I'm developing a jsf application with eclipse and i have a problem.
I have to import a txt file with this format

string string string string
string double double double
string double double double
string double double double
etc....

The file is composed by a first row that has 4 columns of string type
and other rows of 4 columns with first column string and the others
double.
I have to define 2 object, a first headline object that is an array of
string, for storing the first row, and a second object that is composed
by a string field and by an array of double.

Code:
Headline string[]=new string[4];
public class row{
	String geneid=null;
	values double[]=null;
}
public void row(String idGene,double[3] x ) {
this.geneid=idPr;
this.values=x;
}
This code is correct?
For storing my file i need an headline array of string and an arraylist
of row objects.
How can populate them with the txt file?
I've loaded the file with
Code:
BufferedReader br = new BufferedReader(new
InputStreamReader(myFile.getInputStream()));

Can you help me with some code?I'm not expert....

I think you've asked this same question or one very close to it several
times in the last several days. I think you've received answers most of
those times. Why aren't you following the suggestions people have given
you? This isn't a terribly difficult problem and I don't expect that
people will keep answering the question for you forever....
 
O

Oliver Wong

gbattine said:
Hi guys,
i'm a new java user and i have a big question for you.
I'm developing a jsf application with eclipse and i have a problem.
I have to import a txt file with this format

string string string string
string double double double
string double double double
string double double double
etc....

The file is composed by a first row that has 4 columns of string type
and other rows of 4 columns with first column string and the others
double.
I have to define 2 object, a first headline object that is an array of
string, for storing the first row, and a second object that is composed
by a string field and by an array of double.

Code:
Headline string[]=new string[4];
public class row{
String geneid=null;
values double[]=null;
}
public void row(String idGene,double[3] x ) {
this.geneid=idPr;
this.values=x;
}
This code is correct?
For storing my file i need an headline array of string and an arraylist
of row objects.
How can populate them with the txt file?
I've loaded the file with
Code:
BufferedReader br = new BufferedReader(new
InputStreamReader(myFile.getInputStream()));

Can you help me with some code?I'm not expert....

It's weird. It seems like every other week, you're doing a different
variant on the same problem.

Anyway, if you've solved the previous problem, solving this one should
be easy. It's just like the last one, except instead of an arbitrary number
of columns, you have exactly 3 (or 4, depending on whether you count the
labeling columns).

- Oliver
 
G

gbattine

Excuse me guys
for my repetitive questions, but my problem don't has solution..
My question now is:

I'm using this routine to calculate
public String processMyFile() throws IOException {
BufferedReader br = new BufferedReader(new
InputStreamReader(myFile.getInputStream()));
String line = null;
while ((line = br.readLine()) != null) {
line = line.replace (',', '.');
row++;
StringTokenizer st = new StringTokenizer(line);
numberOfNumericColumns = (st.countTokens()-1);
col=(numberOfNumericColumns+1);

//dichiaro l'oggetto intestazione

to calculate number of rows and columns and it works fine.
I've defined 2 objects

headline string[]=new string[col];

public class riga{
String geneid;
values double[]=null;
}

Arraylist<riga> linee=new Arraylist<linee>();

that represents the first row(headline) and the other rows (riga).
My question is:
how can i modify my code to load txt file into the object headline and
into the arraylist linee?
Excuse me for disturb,please help me with code if it's
possible....thanks
 
O

Oliver Wong

gbattine said:
Excuse me guys
for my repetitive questions, but my problem don't has solution..

It'd probably be easier to solve your problem if it didn't keep changing
every day. How are you able to do this? Is your client changing his/her
mind? Or are did you manager to convince the teacher that the assignment is
too difficult, or what?

If you keep changing your problem, I get very discouraged about helping
you, because if I invest, say 2 hours, to explain to you how to sovle your
problem, the next day you'll just post a completely new problem and I
wouldn't have ended up helping you anyway. That's 2 hours wasted that I
could have spent helping someone else.
My question now is:

I'm using this routine to calculate
public String processMyFile() throws IOException {
BufferedReader br = new BufferedReader(new
InputStreamReader(myFile.getInputStream()));
String line = null;
while ((line = br.readLine()) != null) {
line = line.replace (',', '.');
row++;
StringTokenizer st = new StringTokenizer(line);
numberOfNumericColumns = (st.countTokens()-1);
col=(numberOfNumericColumns+1);

//dichiaro l'oggetto intestazione

to calculate number of rows and columns and it works fine.
I've defined 2 objects

headline string[]=new string[col];

public class riga{
String geneid;
values double[]=null;
}

Arraylist<riga> linee=new Arraylist<linee>();

that represents the first row(headline) and the other rows (riga).
My question is:
how can i modify my code to load txt file into the object headline and
into the arraylist linee?
Excuse me for disturb,please help me with code if it's
possible....thanks

Your braces aren't balanced, and there's no return statement, although
the method is declared as returning a string. It'll be easier if you post an
SSCCE: http://mindprod.com/jgloss/sscce.html

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,534
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top