Populate an arraylist....

Discussion in 'Java' started by gbattine, Jun 12, 2006.

  1. gbattine

    gbattine Guest

    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....
     
    gbattine, Jun 12, 2006
    #1
    1. Advertising

  2. gbattine

    Henry Guest

    gbattine wrote:
    > 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....

    --
    Henry
     
    Henry, Jun 12, 2006
    #2
    1. Advertising

  3. gbattine

    Oliver Wong Guest

    "gbattine" <> wrote in message
    news:...
    > 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
     
    Oliver Wong, Jun 12, 2006
    #3
  4. gbattine

    gbattine Guest

    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
     
    gbattine, Jun 12, 2006
    #4
  5. gbattine

    Oliver Wong Guest

    "gbattine" <> wrote in message
    news:...
    >
    > 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
     
    Oliver Wong, Jun 13, 2006
    #5
    1. Advertising

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

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Saravanan Rathinavelu

    Iterate through ArrayList using an another ArrayList

    Saravanan Rathinavelu, Aug 16, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    2,741
    Natty Gur
    Aug 19, 2003
  2. Kaidi
    Replies:
    4
    Views:
    2,382
    Kaidi
    Jan 3, 2004
  3. Eduardo
    Replies:
    4
    Views:
    9,794
    Andrew Thompson
    Sep 19, 2004
  4. xz
    Replies:
    16
    Views:
    2,375
  5. Enjoy Life
    Replies:
    2
    Views:
    277
    Roland Hall
    Feb 23, 2005
Loading...

Share This Page