This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes How to print the elements of an arraylist that contains a hashmap Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "How to print the elements of an arraylist that contains a hashmap" Watch "How to print the elements of an arraylist that contains a hashmap" New topic
Author

How to print the elements of an arraylist that contains a hashmap

Ayan Biswas
Ranch Hand

Joined: Jul 10, 2010
Posts: 104
I have ArrayList<HashMap>.the HashMap stores(String,Integer) as (key ,value) pair.how will I display all the elements of the arraylist.


AyanBiswas
Claudiu Chelemen
Ranch Hand

Joined: Mar 25, 2011
Posts: 71

Hi Ayan.

If you simply use a System.out.println() on the list, it displays quite nice.
In case you need some kind of formatted output, please detail.

Cheers,
Claudiu
Harsha Smith
Ranch Hand

Joined: Jul 18, 2011
Posts: 287
Ayan Biswas
Ranch Hand

Joined: Jul 10, 2010
Posts: 104

Sorry,for not being precise with my query.
Actually,I need to access each (KEY,VALUE) pair from each hashmap and then do some updation on the elements of each hashmap and then display it.
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3068
    
  33

Ayan Biswas wrote:
Sorry,for not being precise with my query.
Actually,I need to access each (KEY,VALUE) pair from each hashmap and then do some updation on the elements of each hashmap and then display it.


You would have to iterate through the list- you can use Enhanced for loop. so you get HashMap instances on each iteration, use it to get the key-value pairs.
So if you can convert this into code, we would be able to help you further


Mohamed Sanaulla | My Blog
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: How to print the elements of an arraylist that contains a hashmap
 
Similar Threads
Regarding sorting data in arraylist
Make HashMap elements fit into an ArrayList
Any Link Between ArrayList and HashMap
Adding Elements
how to use logic:iterator tag inorder to iterate ArrayList consisting of HashMap