Java Overview

Table of Contents

1. Java Overview

1.1. 风格

class Util {
    int mX;
    int mData;
    static int sValue;
    public void helloWorld() {

    }
}

1.2. 变量

  • int x=10;

1.3. 函数

  • int test(int a, int b) {}

1.4. 输入输出

1.5. 类型及转换

1.5.1. 基本类型

  • boolean, byte, char, int, long, float, double
  • array: int [] x={1,2,3}; int [] x=new int[]{1,2,3}; int [] x=new int[3];

1.5.2. 复杂类型

  • String, Collection, List, ArrayList, Map, HashMap, TreeMap, Set, HashSet, TreeSet, ArrayDeque, Stack
  • Class

1.5.3. 转换

1.6. 分配与释放

1.7. string

  • String x="hello"; String x=new String("hello"); String x = new String(byte[]{})
  • "hello"+"world"
  • "Hello".charAt()
  • "Hello".get_bytes() -> byte[]
  • String::split() -> String []
  • String.join(",", new String[] {"a"})
  • String.valueOf(12);
  • Integer.parseInt("12")
  • String.format

1.8. iterator

1.9. array 与 List

  • int [] x;
  • 二维数组: int [][] x = new int[2][3]; int [][] x = {{1, 2}, {3, 4}};
  • Arrays.asList(array) 转换为 List
  • List.toArray(new Integer[0])
  • array[0], array.length
  • List.get(), List.set(), List.size(), List.isEmpty()
  • List.subList
  • List.add(), List.remove(), List.addAll()
  • slice: List.subList, Arrays.copyOfRange

1.10. enum & match

1.11. 控制结构

  • for (int =0; i<10; i++) {}
  • for (int x; new int[]{1,2,3}) {}
  • while, do while

1.12. 抽象数据类型

  • Class Test {int x; int y;};
  • Test x=new Test();

1.13. HashMap

  • new HashMap<int,int>();
  • get(k), containsKey(K)
  • size(), isEmpty()
  • put(K,V), remove(K)
  • keySet(), values(), entrySet()
  • for (Map.Entry entry:m.entrySet() { m.getKey(); m.getValue() }

1.14. Collections

  • Collections.min(List), Collections.max(List), Collections.max(List, Comparator)
  • Collections.reverse(List)
  • Collections.sort(List)
  • Collections.swap(List)

1.15. Arrays

  • Arrays.sort
  • Arrays.toString
  • Arrays.copyOfRange
  • Arrays.asList

1.16. 排序

  • Arrays.sort(new int[]{3,2,1})
  • List.sort(null)
  • List.sort(new Comparator<Ineger> () { int compare(Integer x, Integer y) { return y-x; } }
  • Collections.sort()

1.17. 最大堆

  • PriorityQueue queue=new PriorityQueue()
  • PriorityQueue queue=new PriorityQueue(new Comparator() {…})

1.18. math

1.19. random

1.20. package

  • use std::collections::HashMap
  • use util::*

1.21.

1.22. misc

Author: [email protected]
Date: 2018-10-13 Sat 00:00
Last updated: 2022-02-26 Sat 00:02

知识共享许可协议