• Post Reply Bookmark Topic Watch Topic
  • New Topic

Java Topics Guidance on HashMaps  RSS feed

 
Ranch Hand
Posts: 82
Android
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question : Why cant we not use or print the value just by index in HashMap  ?
Question 2 : After covering these
1.Java Basic
2.OOP
3.Generics
4.Exception Handling
what should a person learn more about java ? and How much java a man has covered just by knowing these above topics in percentage !!! Please type the topics what should a man learn !
 
Sheriff
Posts: 4293
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Question : Why cant we not use or print the value just by index in HashMap

Maps organise data into keys and values.  HashMap implements Map by using a hash.  A good hash produces a number that broadly scratters the data across its domain.  So there is no index.

Do you want to print the Map values insertion order?

what should a person learn more about java ?

You might benefit from a good Java book at this point, like Effective Java.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when should one use HashMap instead of ArrayList?
 
Knute Snortum
Sheriff
Posts: 4293
127
Chrome Eclipse IDE Java Postgres Database VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
An ArrayList holds one type of datum and is accessed sequentially (normally).  A Map is accessed by keys.  So if you have a key/value relationship with the data, use a Map.  When the data are to be accessed sequentially, use a List.
 
kunlex jacoby
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Knute Snortum
 
Saloon Keeper
Posts: 3330
46
Eclipse IDE Firefox Browser Java MySQL Database VI Editor Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you need to look up values by key then a Map (e.g. HashMap) is the correct tool. If you also need to access the data in the order it was added you can use LinkedHashMap.
 
Marshal
Posts: 56608
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hope I am not too late to welcome you to the Ranch
Have a look in the Java™ Tutorials. I expect that will help you.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!