Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java Entry语句的功能是什么?_Java_Linked List - Fatal编程技术网

Java Entry语句的功能是什么?

Java Entry语句的功能是什么?,java,linked-list,Java,Linked List,因此,对于列表,我是个新手,我想知道我是否正确理解了以下代码,更具体地说,Entry语句的功能是什么 是不是因为Entry语句,myList能够接受myHashMap中的条目,以便稍后使用comparator对列表进行排序 List<Entry<String, Integer>> myList = new LinkedList<Entry<String, Integer>>(myHashMap.entrySet()); Collec

因此,对于列表,我是个新手,我想知道我是否正确理解了以下代码,更具体地说,
Entry
语句的功能是什么

是不是因为
Entry
语句,myList能够接受myHashMap中的条目,以便稍后使用comparator对列表进行排序

   List<Entry<String, Integer>> myList = new LinkedList<Entry<String, Integer>>(myHashMap.entrySet());

    Collections.sort(myList, new Comparator<Entry<String, Integer>>(){

        @Override
        public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2){

            return o1.getValue().compareTo(o2.getValue());
        }

    });
List myList=newlinkedlist(myHashMap.entrySet());
Collections.sort(myList,newcomparator(){
@凌驾
公共整数比较(条目o1、条目o2){
返回o1.getValue().compareTo(o2.getValue());
}
});
是不是因为Entry语句,myList能够接受myHashMap中的条目,以便稍后使用comparator对列表进行排序

   List<Entry<String, Integer>> myList = new LinkedList<Entry<String, Integer>>(myHashMap.entrySet());

    Collections.sort(myList, new Comparator<Entry<String, Integer>>(){

        @Override
        public int compare(Entry<String, Integer> o1, Entry<String, Integer> o2){

            return o1.getValue().compareTo(o2.getValue());
        }

    });
没错

如您所知,
HashMap
的结构如下:

{
    key1: value1,
    key2: value2,
    key3: value3,
    ...
}
每个KVP称为
条目
。换句话说,
HashMap
可以由一组
Entry
对象表示。这正是
entrySet
方法所做的。您可以使用
entrySet
将所有KVP作为
Entry
对象获取,将它们放入一个列表中并对它们进行排序。

HasMap以Entry对象的形式存储元素,并且当您创建用于保存Entry对象的列表时,您的列表已经接受了HashMap中的条目集。