Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

incrementing the names of HashMaps? 1

Status
Not open for further replies.

vegman

Programmer
Dec 17, 2003
7
0
0
US
I have 15 hashmaps that I am filling and placing in an array. The names of the hash maps increase numerically as follows.

hBasicCov1
hBasicCov2
hBasicCov3
hBasicCov4 and so on......

I want to process this in a loop and when I to fill each hashmap, I want to fill the next available hashmap and increment the name by one. I thought maybe I could do this by concatenating a string with an integer and incrementing the integer, abd then use this string somehow as my hashmap name, but this doesn't work...

String hBC = "hbasicCov";
String basCovHM = "";
basCovHM = hBC + num1; increment num1 each time thru loop

In other words I want to increment the name of a hashmap and then use the put method on that name. Is this possible in java?

Any ideas?


Thanks.....
 
Instead of an array, you can include the hashmaps on another hashmap, so you can access them by their name (as key).

Code:
HashMap hashOfHashes = new HashMap();

for i {
   hashOfHashes.add("hbasic"+i, hashMap number i);
}

and to access them

Code:
for i {
   hashOfHashes.get("hbasic"+i).put(sthg);
}

Cheers.

Dian
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top