java.util.List

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #46
    [QUOTE=shana07]TQ.Pretty understood List now and also I read List is an interface from a Collection.
    Then, how about an ArrayList can contain other lists .....as what you said?
    Originally posted by r035198x
    All I can say is an ArrayList can contain other lists as elements as well.
    Originally posted by r035198x
    Code:
     ArrayList list = new ArrayList(); 
    list(0) = new ArrayList();
    Coz, my aim here is to create many ArrayList (or list - not sure) with the same variable (ifs1) in loop.
    again, not sure this is possible or not.....
    If you want to create many ArrayLists (they are also lists since ArrayList implements List) then just do as I posted earlier

    either
    Code:
    ArrayList<ArrayList> lists = new ArrayList<ArrayList>(); //preferrable
    or
    Code:
     ArrayList lists = new ArrayList();
    Then add the lists at their positions with
    Code:
     lists(i) = new ArrayList();

    Comment

    • shana07
      Contributor
      • Jan 2007
      • 280

      #47
      Code:
      ArrayList<ArrayList> ifs1 = new ArrayList<ArrayList>(); //preferrable
      found an error:
      java.util.Array List does not take parameters

      Code:
      ArrayList ifs1 = new java.util.ArrayList();
      ......
      int ch = getNumber();
      ifs1(ch) = new ArrayList();
      error: cannot find symbol
      symbol : method ifs1(int)

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #48
        Originally posted by shana07
        Code:
        ArrayList<ArrayList> ifs1 = new ArrayList<ArrayList>(); //preferrable
        found an error:

        java.util.Array List does not take parameters



        Code:
        ArrayList ifs1 = new java.util.ArrayList();
        
        ......
        
        int ch = getNumber();
        
        ifs1(ch) = new ArrayList();
        error: cannot find symbol

        symbol : method ifs1(int)


        Yeah it is supposed to be

        Code:
         ArrayList list = new ArrayList(); 
        
        ifs1.set(index, list);

        Comment

        • shana07
          Contributor
          • Jan 2007
          • 280

          #49
          just to let you know I'm still working on it..by the way,
          making such code, how's the result should I get..
          is that creating more ArrayList using ifs1 variable?

          Comment

          Working...