Results 1 to 2 of 2
  1. #1
    uhertz is offline Member
    Join Date
    Jun 2011
    Posts
    11
    Rep Power
    0

    Default How do you use an arraylist of string arrays

    I need to read a variable number of lines from a text file
    So I cannot use a two dimensional array. Instead, I would like to use an arraylist of array of string where the array has a fixed number of strings. But I get an error msg
    Java Code:
    import java.io.*;
    import java.util.*;
    public class gd
    {
        private String[] data=new String[4];
        private ArrayList<data> rd;
        
        public gd(){
            rd=new ArrayList<data>();
        }
    
        public ArrayList<data> rd(){
            File tf=new File ("rmfile.txt");
            try
            {
                BufferedReader in = new BufferedReader (new FileReader("textfile.txt"));
                String str; int i=0;
                while ((str=in.readLine())!=null){
                   rd.add=str.split(":");
                    i++;
                }
                in.close();
            }
            catch (IOException e){
            }
            return rd;
        }
    }

  2. #2
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,785
    Blog Entries
    7
    Rep Power
    21

    Default Re: How do you use an arraylist of string arrays

    Your ArrayList is of type ArrayList<String[]>, i.e. you mention the type of its elements (here: a String array), not the name of an identifier of that type.

    kind regards,

    Jos
    cenosillicaphobia: the fear for an empty beer glass

Similar Threads

  1. Replies: 12
    Last Post: 11-26-2010, 09:33 AM
  2. Replies: 1
    Last Post: 11-04-2010, 07:53 PM
  3. Replies: 8
    Last Post: 10-08-2010, 08:24 AM
  4. Declaring an ArrayList of Arrays
    By mlad in forum New To Java
    Replies: 6
    Last Post: 03-17-2010, 03:40 AM
  5. Arraylist with arrays?
    By Dieter in forum Advanced Java
    Replies: 13
    Last Post: 09-20-2009, 12:10 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •