Is it possible for us to implement a HashMap with one key and two values. Just as HashMap?
Please do help me, also by telling (if there is no way) any other way to implement the storage of three values with one as the key?
Is it possible for us to implement a HashMap with one key and two values. Just as HashMap?
Please do help me, also by telling (if there is no way) any other way to implement the storage of three values with one as the key?
Yes, this is frequently called a
multimap
.See: http://google-collections.googlecode.com/svn/trunk/javadoc/index.html?com/google/common/collect/Multimap.html
If you use Spring Framework. There is:
org.springframework.util.MultiValueMap
.To create unmodifiable multi value map:
Or use
org.springframework.util.LinkedMultiValueMap
The easiest way would be to use a google collection library:
import com.google.common.collect.ArrayListMultimap; import com.google.common.collect.Multimap;
public class Test {
}
maven link: https://mvnrepository.com/artifact/com.google.collections/google-collections/1.0-rc2
more on this: http://tomjefferys.blogspot.be/2011/09/multimaps-google-guava.html
I use
Map<KeyType, Object[]>
for associating multiple values with a key in a Map. This way, I can store multiple values of different types associated with a key. You have to take care by maintaining proper order of inserting and retrieving from Object[].Example: Consider, we want to store Student information. Key is id, while we would like to store name, address and email associated to the student.
I prefer the following to store any number of variables without having to create a separate class.
Here is THE ANSWER : ) : )
String key= "services_servicename"
ArrayList data;
for(int i = 0; i lessthen data.size(); i++){
I have got the Best Results.
You Just Have to Create New HashMap Like
HashMap servicesNameHashmap = new HashMap();
in Your For Loop. It will have Same Effect Like Same Key And Multiple Values.
Happy Coding :)