zoukankan      html  css  js  c++  java
  • Set

    JAVA中的set有三种:HashSet,TreeSet和LinkedHashSet。

    ①HashSet的输出顺序是不确定的,但是它的速度最快;

    ②TreeSet输出顺序是升序排列的;

    ③LinkedHashSet输出顺序是确定的,就是插入时的顺序。

    HashSet

    package com.sjp.list;
    
    import java.io.Serializable;
    import java.util.HashMap;
    
    /**
     * Created by Timor on 2019/6/24.
     */
    public class MyHashSet<E> implements Serializable {
    
        private static final long serialVersionUID = 394734015309173362L;
    
        private transient HashMap<E,Object> map;
    
        private static final Object PRESENT = new Object();
    
        public MyHashSet() {
            map = new HashMap<E, Object>();
        }
    
        public boolean add(E e) {
            return map.put(e, PRESENT)==null;
        }
    }

    TreeSet

    package com.sjp.list;
    
    import java.io.Serializable;
    import java.util.HashMap;
    import java.util.TreeMap;
    
    /**
     * Created by Timor on 2019/6/24.
     */
    public class MyTreeSet<E> implements Serializable {
    
        private static final long serialVersionUID = 394734015309173362L;
    
        private transient TreeMap<E,Object> map;
    
        private static final Object PRESENT = new Object();
    
        public MyTreeSet() {
            map = new TreeMap<E, Object>();
        }
    
        public boolean add(E e) {
            return map.put(e, PRESENT)==null;
        }
    }
  • 相关阅读:
    CentOS7最小化安装后要做的事
    Django 2.0 新特性
    Django2.+ path配置
    Django 安装
    Django基础
    http协议
    Centos7 下mysql大小写敏感问题
    CentOS 设置mysql的远程访问
    Linux下彻底卸载mysql详解
    静态库和动态库
  • 原文地址:https://www.cnblogs.com/sjp007/p/11078235.html
Copyright © 2011-2022 走看看