Two D Array list

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • maralfarshadi
    New Member
    • Jul 2007
    • 14

    Two D Array list

    Dear All

    Could you please explain or refer some reading material on how to create two dimensional array lists ? and how to access the fields with columns and row indexes ?


    Extremely appreciate your help
    Maral
  • JosAH
    Recognized Expert MVP
    • Mar 2007
    • 11453

    #2
    Originally posted by maralfarshadi
    Dear All

    Could you please explain or refer some reading material on how to create two dimensional array lists ? and how to access the fields with columns and row indexes ?


    Extremely appreciate your help
    Maral
    You can implement a two dimensional list as a list that contains (other) lists:
    Since Lists are ordinary objects you can store those Lists in the 'major' list:

    [code=java]
    List<List<T>> matrix= new ArrayList<List< T>>();
    [/code]

    kind regards,

    Jos

    Comment

    • Ganon11
      Recognized Expert Specialist
      • Oct 2006
      • 3651

      #3
      Originally posted by JosAH
      [code=java]
      List<List<T>> matrix= new ArrayList<List< T>>();
      [/code]
      Out of curiosity, will you have to insert spaces with all those <'s and >'s, e.g.

      [CODE=java]List< List< T > > matrix= new ArrayList< List< T > >();[/CODE]

      I know you have to do this in C++, as the compiler thinks you are using >>, the bit shift operator.

      Comment

      • JosAH
        Recognized Expert MVP
        • Mar 2007
        • 11453

        #4
        Originally posted by Ganon11
        Out of curiosity, will you have to insert spaces with all those <'s and >'s, e.g.

        [CODE=java]List< List< T > > matrix= new ArrayList< List< T > >();[/CODE]

        I know you have to do this in C++, as the compiler thinks you are using >>, the bit shift operator.
        No there's no need to; I know C++ is a bit stupid w.r.t. this, i.e. it uses C's own
        lexical analyzer (which is the stupid part); Sun managed to solve this little
        idiosyncracy nicely in Java; no spaces are needed here.

        kind regards,

        Jos

        Comment

        Working...