Required:
http://commons.apache.org/proper/commons-collections/
Source Code
import java.util.Set;
import java.util.Map;
import java.util.Iterator;
import java.util.List;
import org.apache.commons.collections.map.MultiValueMap;
public class MultiMapExample {
public static void main(String[] args) {
MultiValueMap mp=new MultiValueMap();
mp.put("a", 10);
mp.put("a", 11);
mp.put("a", 12);
mp.put("b", 13);
mp.put("c", 14);
mp.put("e", 15);
List list = null;
Set set = mp.entrySet();
Iterator i = set.iterator();
while(i.hasNext()) {
Map.Entry me = (Map.Entry)i.next();
list=(List)mp.get(me.getKey());
for(int j=0;j<list.size();j++)
{
System.out.println(me.getKey()+": value :"+list.get(j));
}
}
}
}
Results:
a: value :10
a: value :11
a: value :12
c: value :14
b: value :13
e: value :15
Java - Duplicate key in java collection (Map, HashMap)
Related Posts:
How to Scale a jQuery Mobile Site for iOSThe first issue was that the site wasn’t scaling properly when it first loaded and everything was so small that I could barely click on it with my finger. Certainly, this is not what I’d call optimal for a mobile si… Read More
Create GUID in JavaScript Case 1: jquery.guid.js var guid = jQuery.Guid.New() but sometimes, it return an error Guid is undefined, etc ... Case 2: function S4() { return (((1+Math.random())*0x10000)|0).toStr… Read More
Java to Json to JavaScript ObjectGson gson = new Gson();String jsonString= gson.toJson(JavaObject);javaScriptObject = JSON.parse(jsonString);… Read More
How to convert Java object to / from JSON (Gson)JSON is stand for JavaScript Object Notation, it is a lightweight data-interchange format. You can see many Java applications started to throw away XML format and start using json as a new s data-interchange format. Java i… Read More
response.setContentTypeapplication/json application/x-javascript text/javascript text/x-javascript text/x-json … Read More
0 comments:
Post a Comment