How to create a 2 way map in java

前端 未结 6 1635
无人共我
无人共我 2020-11-28 09:42

I need a data structure to store string-int value pairs in an 1:1 relationship, and being able too look up from either way their counterpart.

I wrote a class with a

6条回答
  •  余生分开走
    2020-11-28 10:24

    Using Guava,

        HashBiMap map = HashBiMap.create();
    
        map.put("name", "Sohail");
        map.put("country", "Pakistan");
    
        Log.d("tag", "name is " + map.get("name"));
    
    
        BiMapinvmap= map.inverse();
    
        Log.d("tag", "Pakistan is a " + invmap.get("Pakistan"));
    

    read complete tutorial here.

提交回复
热议问题