• 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
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Devaka Cooray
  • Ron McLeod
  • paul wheaton
Saloon Keepers:
  • Tim Moores
  • Piet Souris
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Frits Walraven
  • Scott Selikoff

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.
 
This tiny ad will self destruct in five seconds.
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic