• 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:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Map within a List  RSS feed

 
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hiya,

i want to get a linkedhashmap within a linkedlist but it wont work :-(

i have tried

List<Map<String, String>> list = new LinkedList<HashMap<String, String>> ();

whats the best way?

cheers
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Nail,

This is my first reply in this forum and I hope it be beneficial.

I think it is not possible to apply polymorphism on the Type of the generic collection; the generic Type has to be the same. so this I think it will work
List<HashMap<String, String>> list = new LinkedList<HashMap<String, String>>
 
Wanderer
Sheriff
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or:
 
Sheriff
Posts: 21460
96
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As Jim said, just use Map<String,String> on the right side as well.

The declaration does not care about which type of map you use, all it cares about is that you want to add Map<String,String> objects. Now why should your initialization be more restrictive than that?
If you really need it to be restricted to HashMap<String,String> you should also declare it as HashMap<String,String>.
 
Niall Loughnane
Ranch Hand
Posts: 209
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sound thanks a million for your replies
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!