Java entry

我希望要一个ArrayList<Entry>,类似C++中的pair,

但是Map.Entry是个接口,不能实例化,可以像下面这样写

HashMap<Integer, Integer> G = new HashMap<Integer,Integer>();
G.put(1, 9); G.put(4, 6); G.put(2, 8);G.put(3, 7);    
ArrayList<Map.Entry<Integer, Integer>> arrayList = new 
        ArrayList<Map.Entry<Integer, Integer>(G.entrySet());

但是这个map完全不是我需要的,然后看到这里http://stackoverflow.com/questions/3110547/java-how-to-create-new-entry-key-value

于是可以这么写:

ArrayList<Map.Entry<Integer, Integer>> arrayList = new 
    ArrayList<Map.Entry<Integer, Integer>>();
arrayList.add(new AbstractMap.SimpleEntry(1, 9));
原文地址:https://www.cnblogs.com/fstang/p/3032097.html