正文
1. 基础运算
Integer.INT_MAX;
Integer.INT_MIN;
long name;
(int)n1%(int)n2;
复制
2. 字符串类
String s_name = "";
String s=String.valueOf(int);
String.length();
String.charAt(index);
string.toCharArray(str);
String.substring(start_index,end_index);
String1 + String2;
string1.concat(string2);
for(char c:string.toCharArray()){}
for(int i=0;i<string.length();i++){
string.charAt(i);
……
}
StringBuffer Name=new StringBuffer();
StringBuffer.append(ch);
StringBuffer.toString();
StringBuilder Name=new StringBuilder();
StringBuilder.append(char/String);
StringBuilder.toString();
StringBuilder.reverse();
复制
3. 数组类与链表
int[] array_Name = new int[length];
int[] array_name=new int[]{初始的元素值};
int N=array.length;
array[index];
int[][] name=new int[line_size][row_size];
int line=array.length;
int row=array[0].length;
Class Node {
int val;
Node next;
public Node(int val){
this.val=val;
this.next=null;
}
}
Node node=new Node(value);
ListNode.val;
ListNode.next;
LinkedList<E> LLName=new LinkedList<E>();
LinkedList<E> listname=new LinkedList<E>(oldlist);
LinkedList.remove();
LinkedList.remove(index);
LinkedList.add(element);
LinkedList.isEmpty();
LinkedList.size();
ArrayList<E> AL_Name = new ArrayList<E>();
ArrayList.add(element);
ArrayList.remove(index);
ArrayList.get(index);
ArrayList.size();
ArrayList.indexOf(element);
复制
4. 栈和队列
Stack<E> stackName=new Stack<E>();
Stack.push(element);
Stack.pop();
Stack.empty();
LinkedList<> queue_name=new LinkedList<>();
queue_name.add();
queue_name.poll();
queue_name.size();
复制
5. 字典类
HashMap<type,type> HM_Name = new HashMap<type,type>();
HashMap<type,type> HM_Name = new HashMap<type,type>(){{put(key,value);put(key,value);}};
HashMap.put(key,value);
HashMap.get(key);
HashMap.containsKey(key);
复制
6. 树
public class TreeNode {
int val;
TreeNode left;
TreeNode right;
TreeNode(int x) { val = x; }
}
A.value;
A->value;
A==null;
root.left;
root.right;
root.val;
复制