【JAVAEE】java_6_集合

  • Collection

    remove removeAll retainAll(修改当前集合为交集) equals hashCode toArray(返回数组) iterator add addAll isEmpty size clear contains(调用obj对象所拥有的equals方法) containsAll
    
  • Collections

    • Collections.reverse(List)
    • Collections.sort
    • Collections.sort(List, Comparator)
    • Collections.max
    • Collections.max(List, Comparator)
    • min
    • frequency(Collection, obj) 出现次数
    • copy
    • synchronizedXxx
  • Iterator

    • hasNext next(最开始在第一个元素之前 指针先下移并返回对应的元素) remove
    while (hasNext) {
     next;
    }
    
    for (Object obj : list) {
     obj++; //因为obj是局部变量 所以list中的元素不变
    }
    
  • List

    add(index, element) addAll(index, collection) get(index) indexOf(obj) 首次出现 没有-1 lastIndexOf remove(index) 按索引 set(index, element) List subList(int from, int to)
    
  • Set没有定义额外的方法 向Set方法添加的元素需要重写hashcodeequals

  • Map

    put putAll get remove(obj) clear size containsKey containsValue isEmpty equals(Map)
    
    • 遍历key Set set = map.keySet()
    • 遍历value Collection values = map.values()
    • 遍历key-value Set set = map.entrySet()
    foreach(Map.Entry i : set) {
    	i.getKey
    	i.getValue
    }
    
  • 有序可重复

  • ArrayList 线程不安全 效率高 初始化10 1.5倍扩容 JDK8中初始化为空 第一次add时为10

  • LinkedList 底层使用双向链表

  • Vector 古老实现类 线程安全

  • HashSet 线程不安全 可以存储null 无序性HashCode 不可重复equals 7上8下 初始化16

添加a计算哈希值 判断此位置上的链表是否哈希值相同 如果相同 比较equals 如果都不同则插入a

  • LinkedHashSet 双向链表 遍历内部数据时 可以按照添加的顺序

  • TreeSet 用红黑树存储 放入的数据是同一类可排序的 按照添加的类的属性排序 在此容器中判断是否相同不用equals而用compareTo返回0、compare返回0

  • TreeSet t = new TreeSet(new Comparator() {})

  • Map

  • HashMap 线程不安全 效率高 可以存储nullkey/value

Entry[] 初始化16 计算key的hashcodeequals比较是否相同

扩容为2倍

JDK8Node[] 开始为空 第一次添加为16

链表大于8且数组长度大于64 则变为红黑树 加载因子0.75 扩容:负载因子乘以长度 超过长度且存储的位置在数组上非空则扩容

  • LinkedHashMap 继承了HashMap的Node 增加了beforeafter

  • TreeMap key为同一类对象 按照key使用自然排序或定制排序 底层红黑树

  • Hashtable 古老的 线程安全 效率低 不可以存储null的key/value

  • Properties key和value都是String类型

  • a=b 不要加空格

    class Test2 {
        public static void main(String[] args) throws Exception {
            Properties properties = new Properties();
            FileInputStream file = new FileInputStream("jdbc.properties");
            properties.load(file);
            String name = properties.getProperty("name");
            System.out.println(name);
            properties.setProperty("name2", "hhh");
            name = properties.getProperty("name");
            System.out.println(name);
            file.close();
        }
    }
    
    class Test2 {
        public static void main(String[] args) throws Exception {
            Properties properties = new Properties();
            ClassLoader classLoader = Test2.class.getClassLoader();
            //默认在src下面 方式1在工程下
            InputStream in = classLoader.getResourceAsStream("jdbc.properties");
            properties.load(in);
            String name = properties.getProperty("name");
            System.out.println(name);
            properties.setProperty("name2", "hhh");
            name = properties.getProperty("name");
            System.out.println(name);
        }
    }
    
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值