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:
Tim Cooke
Campbell Ritchie
paul wheaton
Ron McLeod
Devaka Cooray
Sheriffs:
Jeanne Boyarsky
Liutauras Vilda
Paul Clapham
Saloon Keepers:
Tim Holloway
Carey Brown
Piet Souris
Bartenders:
Forum:
Beginning Java
Map.Entry
AJ sisodia
Greenhorn
Posts: 16
posted 19 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 19 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 19 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!
Did you see how Paul
cut 87% off of his electric heat bill with 82 watts of micro heaters
?
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...