Search...
FAQs
Subscribe
Pie
FAQs
Recent topics
Flagged topics
Hot topics
Best topics
Search...
Search within Beginning Java
Search Coderanch
Advance search
Google search
Register / Login
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
Paul Clapham
Ron McLeod
Jeanne Boyarsky
Tim Cooke
Sheriffs:
Liutauras Vilda
paul wheaton
Henry Wong
Saloon Keepers:
Tim Moores
Tim Holloway
Stephan van Hulst
Carey Brown
Frits Walraven
Bartenders:
Piet Souris
Himai Minh
Forum:
Beginning Java
Map.Entry
AJ sisodia
Greenhorn
Posts: 16
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
can't understand how to make use of "Map.Entry".Pls help by giving simple examples.
Jesper de Jong
Java Cowboy
Posts: 16084
88
I like...
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
Can you please be more specific about what you don't understand? Do you have some code and it doesn't work? If so, post the code, so that we can tell you what's wrong with it. Here's a simple example, iterating a Map:
Map map = new HashMap(); // ...fill the map // Iterate the map Iterator i = map.entrySet().iterator(); while (i.next()) { Map.Entry e = (Map.Entry) i.next(); System.out.println("key=" + e.getKey() + ", value=" + e.getValue()); }
Jesper's Blog
-
Pluralsight Author Page
Jeff Albertson
Ranch Hand
Posts: 1780
posted 16 years ago
Number of slices to send:
Optional 'thank-you' note:
Send
import java.util.*; public class Test { public static void main(String[] args) { example_pre_1_5(); example(); } static void example_pre_1_5() { Map m = new TreeMap(); m.put("A","apple" ); m.put("B","banana"); m.put("C","cherry"); //alter every value using its key for(Iterator i = m.entrySet().iterator(); i.hasNext(); ) { Map.Entry e = (Map.Entry) i.next(); e.setValue(e.getKey() + " is for " + e.getValue()); } System.out.println(m); } static void example() { Map<String, String> m = new TreeMap<String, String>(); m.put("A","apple" ); m.put("B","banana"); m.put("C","cherry"); //alter every value using its key for(Map.Entry<String, String> e : m.entrySet()) e.setValue(e.getKey() + " is for " + e.getValue()); System.out.println(m); } }
There is no emoticon for what I am feeling!
Hey! Wanna see my flashlight? It looks like this tiny ad:
free, earth-friendly heat - a kickstarter for putting coin in your pocket while saving the earth
https://coderanch.com/t/751654/free-earth-friendly-heat-kickstarter
reply
reply
Bookmark Topic
Watch Topic
New Topic
Boost this thread!
Similar Threads
Class Cast Exception for Map.Entry
sorting..
Class Cast Exception for Map.Entry
more generics
Generics Question: Map and Map.Entry
More...