跳转至

数据类型

变量类型决定占据内存空间的大小。

数组

//数据遍历
public static void main(String[] args) {
    int[] arr = new int[4];
    arr[0] = 15;
    arr[1] = 98;
    for (int num:arr){
        System.out.println(num);
    }
}
//15 98 0 0

集合(容器)

Collection

  • List

  • CopyOnWriteArrayList

  • Vector、Stack

  • ArrayList

  • LinkedList

  • Set

  • HashSet、LinkedHashSet

  • SortedSet、TreeSet
  • EnumSet
  • CopyOnWriteArraySet
  • ConcurrentSkipListSet
  • Queue

  • Deque

    • ArrayDeque

    • BlockingDeque、LinkedBlockingDeque

  • BlockingQueue

    • ArrayBlockingQueue

    • PriorityBlockingQueue

    • LinkedBlockingQueue

    • TransferQueue、LinkedTransferQueue

    • SynchronousQueue

    • DelayQueue

  • PriorityQueue

  • ConcurrentLinkedQueue

Map

  • HashMap、LinkedHashMap
  • TreeMap
  • WeakHashMap
  • IdentityHashMap
  • ConcurrentHashMap
  • ConcurrentSkipListMap
public static void main(String[] args) {
    //定义一个集合
    ArrayList list = new ArrayList();
    System.out.println(list);
    //add
    list.add("aaa");
    list.add("bbb");
    list.add("ccc");
    list.add("ddd");
    System.out.println(list);
    //删
    list.remove("bbb");
    System.out.println(list);
    //改
    list.set(0, "eee");
    System.out.println(list);
    //查看
    System.out.println(list.get(2));
    //遍历
    for (int i = 0; i <= list.size() - 1; i++) {
        System.out.println(list.get(i));
    }
}