Java常用api
# Class HashMap<T1, T2>
// 创建HashMap对象
HashMap<K, V> map = new HashMap<K, V>();
// 添加键值对
map.put(key, value);
// 获取键对应的值
V value = map.get(key);
// 移除键值对
map.remove(key);
// 判断是否包含某个键
boolean containsKey = map.containsKey(key);
// 判断是否包含某个值
boolean containsValue = map.containsValue(value);
获取HashMap中键值对的数量
int size = map.size();
// 替换value,返回旧value
V value = map.replace(key,value);
// 清空HashMap
map.clear();
// 遍历所有的键
for (K key : map.keySet()) {
System.out.println(key);
}
// 遍历所有的值
for (V value : map.values()) {
System.out.println(value);
}
// 遍历所有的键值对
for (Map.Entry<K, V> entry : map.entrySet()) {
K key = entry.getKey();
V value = entry.getValue();
System.out.println(key + ":" + value);
}
# Class Stack
Stack<Integer> stack = new Stack<>();
public void push(E e);
public E pop();
public int size();
public E peek();
public boolean empty();
# Class PriorityQueue
PriorityQueue(Comparator<? super E> comparator);
public boolean offer(E e);
public E peek();
public E poll();
# Interface Queue
boolean offer(E e);
E poll();
E peek();
# Class ArrayDeque
boolean offerFirst(E e);
boolean offerLast(E e);
E pollFirst();
E pollLast();
E peekFirst()
E peekLast()
int size();
boolean isEmpty();