• Post Reply Bookmark Topic Watch Topic
  • New Topic

How we get Members from HashMap by using Iterator?  RSS feed

 
Salman Mushtaq
Greenhorn
Posts: 27
Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi everyone ,,, today i have face a new problem ,,, that is actually new for me but may be not for you , so the problem is that how we get members from HashMap using iterator ,,,
please give me the full syntax ,,, let i have

HashMap<String,Object> hm = new HashMap<String,Object>();
hm.put("1",Obj);
hm.put("2",obj); . . . etc

now how i get ..//..//
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why use an iterator? Just loop over the entry set. Each loop instance will be an instance of Map.Entry.
 
Salman Mushtaq
Greenhorn
Posts: 27
Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Bear Bibeault wrote:Why use an iterator? Just loop over the entry set. Each loop instance will be an instance of Map.Entry.


How can i do with simple loop i mean where i can write key ,,,, please give me syntax ,, or elaborate your answer ,,, i have very little knowledge of programming ,,,,
 
Paul Clapham
Sheriff
Posts: 22841
43
Eclipse IDE Firefox Browser MySQL Database
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In the Oracle Collections tutorial there are examples of typical ways of accessing Maps. Have a look at that.
 
Mansukhdeep Thind
Ranch Hand
Posts: 1163
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome Salman. Firstly, we are here to guide and not to provide ready made answers. You would have to study the language basics first and be clear with the fundamentals such as declarations, flow constructs, constructors, exceptions, inheritance, interfaces etc.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66307
152
IntelliJ IDE Java jQuery Mac Mac OS X
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The basic idea, let's say we have a Map<String,String> in items:

 
Salman Mushtaq
Greenhorn
Posts: 27
Notepad
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mansukhdeep Thind wrote:Welcome Salman. Firstly, we are here to guide and not to provide ready made answers. You would have to study the language basics first and be clear with the fundamentals such as declarations, flow constructs, constructors, exceptions, inheritance, interfaces etc.


Thank you very much for welcome me on the forum , yes i have some basic knowledge of all these but not know how i implement my little knowledge practically ... and i don't need ready made code but i only see the example to understand the syntax ,, i am little bit confused between ArrayList , Vector amd HashMap .... their uses and their difference ,.,...
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Salman Mushtaq wrote: i am little bit confused between ArrayList , Vector amd HashMap .... their uses and their difference ,.,...


ArrayList has the same functionality as Vector, but it replaces Vector as of the introduction of the Collections Framework in Java 1.2 around 1998. The only time you should use Vector is when you are required to for interacting with legacy code.

ArrayList and Vector are both Lists (java.util.List(←click)), while HashMap is a Map (java.util.Map(←click)). If you read the API docs (click those links), it should become clear what the difference is. If not, you should be able to find plenty with a simple google search. If it's still not clear, ask a more specific question about what you don't understand.
 
Campbell Ritchie
Marshal
Posts: 56592
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I like the section in the Java Tutorials.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!