ASP源码.NET源码PHP源码JSP源码JAVA源码DELPHI源码PB源码VC源码VB源码Android源码
当前位置:首页 >> 网络编程 >> 其他编程教程 >> HashMap 类与内部类实现 Map 接口与内部接口

HashMap 类与内部类实现 Map 接口与内部接口

来源:网络整理     时间:2017-01-03     关键词:

本篇文章主要介绍了" HashMap 类与内部类实现 Map 接口与内部接口",主要涉及到方面的内容,对于其他编程教程感兴趣的同学可以参考一下: public interface Map<K,V> {V get(Object key);V put(K key, V value); interf...

public interface Map<K,V> {
V get(Object key);
V put(K key, V value);
interface Entry<K,V> {
K getKey();
V getValue();
V setValue(V value);
}
}
public class HashMap<K,V> extends AbstractMap<K,V>
    implements Map<K,V>, Cloneable, Serializable {
/**
     * The default initial capacity - MUST be a power of two.
     */
    static final int DEFAULT_INITIAL_CAPACITY = 1 << 4; // aka 16
    /**
     * The maximum capacity, used if a higher value is implicitly specified
     * by either of the constructors with arguments.
     * MUST be a power of two <= 1<<30.
     */
    static final int MAXIMUM_CAPACITY = 1 << 30;
    /**
     * The load factor used when none specified in constructor.
     */
    static final float DEFAULT_LOAD_FACTOR = 0.75f;
/**
     * Basic hash bin node, used for most entries.  (See below for
     * TreeNode subclass, and in LinkedHashMap for its Entry subclass.)
     */
    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;
        }
    }
}

以上就介绍了 HashMap 类与内部类实现 Map 接口与内部接口,包括了方面的内容,希望对其他编程教程有兴趣的朋友有所帮助。

本文网址链接:http://www.codes51.com/article/detail_4191267.html

相关图片

相关文章