• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Two dimenstonal Collections

 
Ranch Hand
Posts: 133
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

Can we use Collections in Two dimenstoanl way ??

I have a two dimentional string arrsy like table (Rows and Columns), so..can i use collections instead of string arrsy ?
If yes then please specify how to iterate 2D Collections also.

Thanks
 
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Nikeshsun Shah,

we have Maps like , HashMap, Hashtable, Properties which will suit to your requirement.
[ August 13, 2007: Message edited by: Srinivasan thoyyeti ]
 
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,

Here is another example that uses "2D" Collections :
// Data entry :
String[][] array = {{ "a11", "a12"},
{ "a21", "a22"}};

// 1rst,you create a List that contains ... Lists
List<List<String>> list2D = new ArrayList<List<String>>();

// 2nd, you populate each list of your list2D
list2D.add(Arrays.asList(array[0]));
list2D.add(Arrays.asList(array[1]));

// Iteration through the list2D List
for(List<String> strList : list2D){
for(String s : strList){
System.out.print(s + " ");
}
System.out.println("");
}

// How to access an individual element :
System.out.println(list2D.get(0).get(1));
 
Srinivasan thoyyeti
Ranch Hand
Posts: 558
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
christian combarel,

Nice example.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic