Results 1 to 9 of 9
  1. #1
    justbeller is offline Member
    Join Date
    Dec 2010
    Posts
    57
    Rep Power
    0

    Post Problem in ArrayList

    I wana use 2 dimensional String in ArrayList lke this

    ArrayList<String[][]> list=new ArrayList<String[][]>();
    but how can i add 2 String in ArrayList

    please help me

  2. #2
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default

    You'd have to create a 2 dimensional array of Strings, then add that to the ArrayList.

    Recommended reading: Arrays (The Java™ Tutorials > Learning the Java Language > Language Basics)
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  3. #3
    justbeller is offline Member
    Join Date
    Dec 2010
    Posts
    57
    Rep Power
    0

    Default

    but i dont know the length of text

  4. #4
    KevinWorkman's Avatar
    KevinWorkman is online now Crazy Cat Lady
    Join Date
    Oct 2010
    Location
    Washington, DC
    Posts
    3,874
    Rep Power
    8

    Default

    Quote Originally Posted by justbeller View Post
    but i dont know the length of text
    I have no idea what you're asking, as you haven't actually described your problem or your question. Post an SSCCE that demonstrates where you're stuck, describe what you're trying to do, describe any problems you're having, and we'll go from there.
    How to Ask Questions the Smart Way
    Static Void Games - Play indie games, learn from game tutorials and source code, upload your own games!

  5. #5
    j2me64's Avatar
    j2me64 is offline Senior Member
    Join Date
    Sep 2009
    Location
    Zurich, Switzerland
    Posts
    962
    Rep Power
    5

    Default

    Quote Originally Posted by justbeller View Post
    but i dont know the length of text

    when you use arrays you should know the length of the elements, otherwise you will never be able to create them.

  6. #6
    justbeller is offline Member
    Join Date
    Dec 2010
    Posts
    57
    Rep Power
    0

    Default

    if you dont length then specially design ArrayList for it
    but I dont how to use 2 dimensional array in ArrayList

  7. #7
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    A 2d array in an arraylist is just a list of lists of lists. Essentially you have created a 3 dimensional array with the first dimension being dynamic. I have no idea what you would do with something like this, but it might be used in this way:
    Java Code:
    //initialize the 2d array
    ArrayList<String[][]> listOfLists = new ArrayList<String[][]>();
    //Do this for every 2d array
    String[][] array2d = new String[10][10];
    array2d[0][0] = "Hi";
    array2d[0][1] = "There";
    array2d[1][0] = "Hello";
    array2d[1][1] = ",";
    array2d[1][2] = "World!";
    //...
    //Do this for every 2d Array
    listOfLists.add(array2d);
    Now, again, why would you want this? This might not be the best data structure for you to use - what are you trying to do?

  8. #8
    justbeller is offline Member
    Join Date
    Dec 2010
    Posts
    57
    Rep Power
    0

    Default

    already done this but im trying to use separate way

  9. #9
    quad64bit's Avatar
    quad64bit is offline Moderator
    Join Date
    Jul 2009
    Location
    VA
    Posts
    1,323
    Rep Power
    7

    Default

    ... im trying to use separate way
    Ok in that case (but only for 'separate way') you need to input all the stuff several times, but only when the smallest is smaller than the largest and only on weekdays.

Similar Threads

  1. Problem- arraylist
    By whizzz in forum New To Java
    Replies: 3
    Last Post: 12-05-2010, 01:13 AM
  2. ArrayList problem.
    By keo in forum New To Java
    Replies: 4
    Last Post: 10-15-2010, 11:22 AM
  3. ArrayList problem
    By brian.baert in forum New To Java
    Replies: 8
    Last Post: 03-06-2010, 01:49 PM
  4. Hey! ArrayList problem here
    By Samgetsmoney in forum New To Java
    Replies: 31
    Last Post: 02-20-2009, 12:39 AM
  5. ArrayList problem
    By khamuruddeen in forum New To Java
    Replies: 7
    Last Post: 12-22-2007, 05:46 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
  •