源码学习(待续)

来源:互联网 发布:泰国和中国的关系 知乎 编辑:程序博客网 时间:2024/05/16 18:03
System.out.println("----------start------------");        System.out.println("----------LIST(Start)------------");        /**         * ArrayList实质是Object[]         * LinkedList         */        List<Integer> arrayList = new ArrayList<>();        List<Integer> linkList = new LinkedList<>();        //List<Integer> arrayListTmp = new ArrayList<>();        //System.out.println(arrayList == arrayListTmp);        //System.out.println(arrayList.hashCode() + "-" + arrayListTmp.hashCode());        System.out.println("----------LIST(End)------------");        System.out.println("----------SET(Start)------------");        /**         * HashSet(){         *     new HashMap<>();         * }         * LinkedHashSet extends HashSet         * 有序体现在迭代器         */        Set<String> hashSet = new HashSet<>();        Set<String> linkedHashSet = new LinkedHashSet<>();        for(int i = 0;i<30;i++) {            hashSet.add(i+"");            linkedHashSet.add(i+"");        }        Iterator<String> iterator = hashSet.iterator();        while(iterator.hasNext()){            System.out.print(iterator.next() + " ");        }        System.out.println("");        iterator = linkedHashSet.iterator();        while(iterator.hasNext()){            System.out.print(iterator.next() + " ");        }        System.out.println("");        System.out.println("----------SET(End)------------");        /**         *static class Node<K,V> implements Map.Entry<K,V> {         *    final int hash;         *    final K key;         *    V value;         *    Node<K,V> next;         *         *    Node(int hash, K key, V value, Node<K,V> next) {         *        this.hash = hash;         *        this.key = key;         *        this.value = value;         *        this.next = next;         *    }         *         *    public final K getKey()        { return key; }         *    public final V getValue()      { return value; }         *    public final String toString() { return key + "=" + value; }         *         *    public final int hashCode() {         *        return Objects.hashCode(key) ^ Objects.hashCode(value);         *    }         *         *    public final V setValue(V newValue) {         *        V oldValue = value;         *        value = newValue;         *        return oldValue;         *    }         *         *    public final boolean equals(Object o) {         *        if (o == this)         *            return true;         *        if (o instanceof Map.Entry) {         *            Map.Entry<?,?> e = (Map.Entry<?,?>)o;         *            if (Objects.equals(key, e.getKey()) &&         *                    Objects.equals(value, e.getValue()))         *                return true;         *        }         *        return false;         *    }         *}         */        Map<String,String> hashMap = new HashMap<>(10);        for(int i = 0; i< 100 ;i++){            hashMap.put("key"+i,"value"+i);        }//        一切对象皆有HashCode//        Integer i = 1;//        i.hashCode();//        hashMap.hashCode();//        String str1 = new String("key");//        String str = new String("key");//        str.indexOf("k");//        System.out.println(str1 == str);//        System.out.println(str1.hashCode() + "-" + str.hashCode());        Map<String,String> linkedHashMap = new LinkedHashMap<>();
原创粉丝点击