This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Java in General and the fly likes convert hashmap <string, anytype > to hashMap<string, object> Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "convert hashmap <string, anytype > to hashMap<string, object>" Watch "convert hashmap <string, anytype > to hashMap<string, object>" New topic
Author

convert hashmap <string, anytype > to hashMap<string, object>

zuje lal
Greenhorn

Joined: Jan 08, 2009
Posts: 1
Can somebody help me to convert any type of "values" , might be integer,string .. To object
I want to keep the key as same and want to convert the value as object
thanks
zuje
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19656
    
  18

Anything that is not a primitive is already an Object. Therefore, Map<String,Integer> is a Map<? extends String,? extends Object>, and you can use it in the putAll method:

Also, most Map implementation classes have a constructor that takes a Map<? extends K,? extends V> so it's even shorter for only one map:


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: convert hashmap <string, anytype > to hashMap<string, object>
 
Similar Threads
how to convert string to int in jsp?
Url from String
How to convert HashMap to JavaBean
Casting to Vs toString()
Difference in "? extends Object" and "Object" in Generics