美文网首页
java.day11

java.day11

作者: 惨不忍睹 | 来源:发表于2016-07-28 16:04 被阅读6次

map 用put来添加键值对有 HashMap TreeMap LinkedHashMap  在存入大量数据时,treeMap最慢HashMap是无序的  TreeMap是有序的 LinkedHashMap 是HashMap的子类,也会排序输出遍历HashMap  用foreach循环 for(Map.Entryentry : hashMap.entrySet()) {      int key = entry.getKey();      String value = entry.getValue();      System.out.println(key + ":" + value);      }和iterator Iterator it = hashMap.entrySet().iterator();      while (it.hasNext()) {      Map.Entryentry = (Entry) it.next();

int key = entry.getKey();

String value = entry.getValue();

System.out.println(key + ":" + value);

}

set 用add添加元素

contains表示 是否包含

retainAll(set)表示求两个集合的交集

ArrayList和LinkedList 的区别

ArrayList 采用数组的形式保存对象,这种方式将对象存放在连续的内存空间里,

[0][1][2][3][4]...[1E5-1] 通过索引搜索和读取数据很快

LinkedList 将对象存放在独立的内存空间,存放了下一个对象和上一个对象的索引[0]->[1]->[2]->[3]...  <-  <-  <-

前者插入和删除数据慢,读取数据块

后者相反

comparable接口,可以将类变成可比较的,可以被排序查找等工具使用

comparator接口 可以实现自定义排序

相关文章

  • java.day11

    map 用put来添加键值对有 HashMap TreeMap LinkedHashMap 在存入大量数据时,tr...

网友评论

      本文标题:java.day11

      本文链接:https://www.haomeiwen.com/subject/uqmajttx.html