0

I need to iterate through a TreeMap.

I won't be able to use another collection instead of a TreeMap, I am merely changing some code in someone else's program. Is it at all possible to do this?

I'm thinking:

while (Treemap.hasNext())

or something similar. Is this possible in Java?

2
Contributors
4
Replies
5
Views
8 Years
Discussion Span
Last Post by P00dle
0

I think I have a solution:

// tm is a TreeMap with values in it
		
		 Set set = tm.entrySet();
			// Get an iterator
			Iterator i = set.iterator();
			// Display elements
			while(i.hasNext()) {
0

Hey thanks! You've been really helpfull. Appreciate it.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.