J2SE 常用方法

1.HashMap<K,V>的常见method;

  • containsKey(Object key)--boolean
  • containsValue(Object value)--boolean
  • put(K key, V value) --插入键值对;
  • remove(Object key)
  • replace(K key, V value) --替换键值对(put其实也可以覆盖)
  • size()--int;
  • get(Object key) --获取键对应的值;

2.HashSet(E);

  • 没有顺序;
  • 元素不能重复;
  • boolean add(E e) --不存在则add,存在则false;
  • boolean contains(Object o)
  • boolean remove(Object o)
  • int size()

3.HashSet vs LinkedHashSet vs TreeSet

  • HashSet: 无序
  • LinkedHashSet: 按照插入顺序
  • TreeSet: 从小到大排序
    • boolean add(E e)
    • boolean contains(Object o)
    • first()  Returns the first (lowest) element currently in this set.
    • last()  Returns the last (highest) element currently in this set.
    • boolean remove(Object o)  Removes the specified element from this set if it is present.
    • size()

4.字符串和数组的转换

  • str.toCharArray() --字符串转换为字符数组
  • String.valueOf(ch) --字符数组转换为字符串

5.字符串String

  • charAt(int index)
  • boolean equals(Object anObject)--Compares this string to the specified object.判断字符串内容是否相同
  • boolean equalsIgnoreCase(String anotherString)--Compares this String to another String, ignoring case considerations. 忽视大小写判断内容
  • int length()--Returns the length of this string.
  • String[] split(String regex)--Splits this string around matches of the given regular expression.分隔字符串
  • char[] toCharArray()--Converts this string to a new character array.字符串转字符数组
  • static String valueOf(char c/char[] data/double d/float f/int i)--Returns the string representation of the xxx argument.--转为字符串

6.栈Stack

  • peek() --Looks at the object at the top of this stack without removing it from the stack.查看栈顶元素
  • pop() --Removes the object at the top of this stack and returns that object as the value of this function.出栈并返回该值
  • push(E item) --Pushes an item onto the top of this stack.入栈
  • empty() --Tests if this stack is empty.
  • search(Object o) --Returns the 1-based position where an object is on this stack.

7.队列Queue

  • offer(E e) Inserts the specified element into this queue if it is possible to do so immediately without violating capacity restrictions.
  • peek() Retrieves, but does not remove, the head of this queue, or returns null if this queue is empty.
  • poll() Retrieves and removes the head of this queue, or returns null if this queue is empty.
  • remove() Retrieves and removes the head of this queue.

8. LinkedList

  • boolean add(E e) Appends the specified element to the end of this list.
  • void add(int index, E element) Inserts the specified element at the specified position in this list.
  • void addFirst(E e) Inserts the specified element at the beginning of this list.
  • boolean contains(Object o) Returns true if this list contains the specified element.
  • boolean isEmpty() Returns true if this list contains no elements.