Java tips

1. Use vars in array dec

int [ ] arr = new int [size];


Type conversion

string to int: 

Integer.parseInt(str)

double to int

(int) num

String split

str.split("-")

uses regular expression,so use "\\."最好

2.sort

Arrays.sort(arr);

Collections.sort(list);


3. length

arr.length;

str.length();

list.size();


4. List, ArrayList:   

List is just an interface, can not be instantiated. It is implemented by ArrayList

See Problem

4 ways to iterate through a list in Java


List<Integer>list = new ArrayList < Integer>();

list.add(3); // add the element at the end

list.add(1,3) // insert the element '3' at index 1 ( the elements behind it are shifted)

list.get(i);   //indexing, starts at 0


5.Stack


你可能感兴趣的:(java)