当我在查阅关于ListView的示例代码时,我遇到了LinkedHashMap。LinkedHashMap是什么,我们可以在哪里使用它,以及如何使用它?我查阅了几篇文章,但并没有完全理解。创建ListView时是否必须使用LinkedHashMap?ListViews和LinkedHashMaps之间有什么联系呢?谢谢。
当我在查阅关于ListView的示例代码时,我遇到了LinkedHashMap。LinkedHashMap是什么,我们可以在哪里使用它,以及如何使用它?我查阅了几篇文章,但并没有完全理解。创建ListView时是否必须使用LinkedHashMap?ListViews和LinkedHashMaps之间有什么联系呢?谢谢。
// suppose we have written a program
.
.
// now use HashMap
HashMap map = new HashMap(); // create object
map.put(1,"Rohit"); // insert values
map.put(2,"Rahul");
map.put(3,"Ajay");
System.out.println("MAP=" +map); //print the output using concatenation
//So the output may be in any order like we can say the output may be as:
Map={3=Ajay,2=Rahul,1=Rohit}
但是在LinkedHashMap中情况并非如此。只需将上述代码中的“HashMap”替换为“LinkedHashMap”,然后查看结果,它将按顺序显示输出,例如1=Rohit将首先显示,然后按顺序显示其他内容。