Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

passing 2D collection objects into 1D collection objects  RSS feed

 
sai rama krishna
Ranch Hand
Posts: 530
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when, where, how, why we need to passing 2D collection objects like hashmap, hashtable, properties into 1D collection objects like arraylist, vector, hasset, sorted set etc and reading back again. What are the practical uses, advantages, disadvanages of doing it.Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance
 
Winston Gutkowski
Bartender
Posts: 10573
65
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
sai rama krishna wrote:when, where, how, why we need to passing 2D collection objects like hashmap, hashtable, properties into 1D collection objects like arraylist, vector, hasset, sorted set etc and reading back again. What are the practical uses, advantages, disadvanages of doing it.Any ideas, suggestions, sample code, links, source code highly appreciated. Thanks in advance

First: the datasets that you list are NOT 2D collections, they're Maps (see java.util.Map). They have entries, each of which has a value (which can be virtually anything), and a key (which must be Comparable; or, in some cases, can be distinguished by a Comparator), which is used to identify the value.

As to passing them into regular collections: there's generally no need. Maps that implement java.util.Map have two methods: keySet(), which returns all the keys in the Map as a Set (see java.util.Set); and values(), which returns all the values in the Map as a Collection (see java.util.Collection).

Winston
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!