File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

HashMap problem

 
Vijay Chandran
Ranch Hand
Posts: 186
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear friends,

I have created a HashMap with no type specifications.
HashMap hashmapObj = new HashMap();

But i want to put values with more than one type.
For example.

hashmapObj.put("key1",StringValue);
hashmapObj.put("key2",ArrayListValue);
hashmapObj.put("key3",InetgerValue); etc.,

When i do like this, compiler produces a warning regarding type safety.
How to handle this without any warnings. I have a condition that i must return only one HashMap object.

Kindly provide your help.
Regards,
Vijay
 
Jesper de Jong
Java Cowboy
Saloon Keeper
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just create the map like this:

Map<String, Object> map = new HashMap<String, Object>();
 
Vijay Chandran
Ranch Hand
Posts: 186
Java
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you very much Jesper
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic