Welcome to the Java Programming Forums

The professional, friendly Java community. 21,500 members and growing!

The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 2 of 2

Thread: Cant set an array value equal to another array value?

  1. #1
    Join Date
    Aug 2011
    Thanked 0 Times in 0 Posts

    Question Cant set an array value equal to another array value?

    I made a Scanner look into a text file (in the text file anything in it would be formatted: string,string,string....). Then, i made a while loop:

         String a = scanner.next();
         String[] split = a.split(",")
         String string = split[0];

    That works fine, but if i were to make the string 'string' an array, and set the first value the same as the first value in split, it would not work...

    My goal is to split the lines in a text file by a comma, then pass each of those values into their own separate array.


    the text files reads: tree,butter,cow,milk

    assuming this is the first line, i want 'tree' to be the first value in one array, 'butter' to be the first value of another array and so on.

  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Thanked 833 Times in 772 Posts
    Blog Entries

    Default Re: Cant set an array value equal to another array value?

    If you don't know how many lines or words per line there will be, try using an ArrayList. You might consider creating a class that represents a table (columns and rows). Java has something similar to this already (see DefaultTableModel (Java Platform SE 6) )

Similar Threads

  1. Doubling The Array Size And Randomizing Array Return
    By Pingu00 in forum What's Wrong With My Code?
    Replies: 18
    Last Post: June 27th, 2011, 10:50 AM
  2. Replies: 2
    Last Post: May 13th, 2011, 03:08 AM
  3. Replies: 2
    Last Post: May 6th, 2011, 05:19 PM
  4. prininting out a 4x4 array according to an order by a 1d array
    By fortune2k in forum Collections and Generics
    Replies: 7
    Last Post: November 25th, 2010, 12:54 PM
  5. 2d (4x4) array insdie a 1d array. (Block cipher)
    By fortune2k in forum Collections and Generics
    Replies: 13
    Last Post: November 23rd, 2010, 05:29 PM

Tags for this Thread