Search code examples
javadictionarycollectionshashmaptreemap

how to insert <interger,string,string> in map (3 inputs) in java


I have an input that is given below. How can I insert these inputs in a map, HashMap preferrably.

{1,"abc","a"} {200,"xyz","b"} {1,"ab","c"} {12,"fgh","d"}

Integer being the key and remaining are values.


Solution

  • add integer value in hasmap as key and other 2 values in list and then add this list to hashmap as key value

    Map<String, String> map = new HashMap<Interger, Object>();
    List<String> maplist1=new ArrayList<String>
                maplist1.add("abc");
                maplist1.add("a");
                map.put(1, maplist1)
               // otherwise clear maplist
               List<String> maplist2=new ArrayList<String>
                maplist2.add("xyz");
                maplist2.add("b");
                map.put(200, maplist2)