栈
Stack stack= new Stack ( ) ;
stack. empty ( ) ;
取出栈顶的元素,不弹出 注意,元素取出时是object类型,需进行类型强转
stack. peek ( ) ;
stack. pop ( ) ;
stack. push ( 元素) ;
stack. size ( ) ;
队列
Queue queue= new queue< > ( ) ;
queue. offer ( 元素) ;
queue. peek ( ) ;
queue. poll ( ) ;
queue. size ( ) ;
数组
String [ ] strs= { "1" , "2" } ;
strs. length;
return new int [ 0 ] ;
二维数组
//二维数组的定义
int[][]ints=new int[][]{{3,2},{2,4}};
ints. length;
Arrays . sort ( arr, ( ( o1, o2) -> {
return o1[ 0 ] - o2[ 0 ] ;
} ) ) ;
字符串
string strs
strs. length ( ) ;
分割字符串,返回值是字符串数组 注意对于特殊分割字符,例如+,-等时,要加上\\转义
strs. split ( "\\\\+" ) ;
set集合
sets. add ( o) ;
sets. contains ( o) ;
Collections 工具类
Person a = new Person ( 'a' , 16 ) ;
Person b = new Person ( 'b' , 17 ) ;
Person c = new Person ( 'c' , 13 ) ;
ArrayList < Person > people = new ArrayList < > ( ) ;
Collections . sort ( people, ( o1, o2) -> {
return o1. age- o2. age;
} ) ;
return Collections . emptyList ( )