Win a copy of Five Lines of Code this week in the OO, Patterns, UML and Refactoring forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Ron McLeod
  • Jeanne Boyarsky
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Liutauras Vilda
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • fred rosenberger
  • salvin francis
Bartenders:
  • Piet Souris
  • Frits Walraven
  • Carey Brown

Map

 
Ranch Hand
Posts: 216
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What is the output of the following program?
import java.util.*;
class Question {
public static void main(String[] args) {
TreeMap map = new TreeMap();
map.put("one","1");
map.put("two","2");
map.put("three","3");
display(map);
}
static void display(TreeMap map) {
Collection c = map.entrySet();
Iterator i = c.iterator();
while(i.hasNext()) {
Object o = i.next();
System.out.print(o.toString());
}
}
}
A)123
B)onetwothree
C)one=1three=3two=2
when i run i get c as the answer
but I did'nt understand how it came ..explain please
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the TreeMap holds elements sorted.
 
The government thinks you are too stupid to make your own lightbulb choices. But this tiny ad thinks you are smart:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic