2020-12-24

1.Arrays類
列表初始化
List<String> stringList = Arrays.asList("a", "b", "c");
排序
Arrays.sort(array);
Arrays.sort(array, Collections.reverseOrder());

匿名對(duì)象實(shí)現(xiàn)Comparator接口的方式
int[][] arr = new int[length][2];
Arrays.sort(arr, new Comparator<int[]>() {
public int compare(int[] o1, int[] o2) {
if(o1[0]==o2[0])
return o1[1]-o2[1];
return o1[0]-o2[0];
}
});

lambda表達(dá)式方式
Arrays.sort(arr, (a,b) -> a[0]==b[0] ? a[1]-b[1] : a[0]-b[0]);

數(shù)組復(fù)制
int[] a2 = a1.clone();

數(shù)組轉(zhuǎn)字符串
Arrays.toString(array)

數(shù)組截取
System.arraycopy(arr2,0,arr1,0,3);
將arr1從0開(kāi)始長(zhǎng)度為3的元素賦值到arr2中長(zhǎng)度從0開(kāi)始的元素

2.隊(duì)列的實(shí)現(xiàn)
Queue<String> queue = new LinkedList<String>();
queue.offer("a")
queue.peek()
queue.poll()
3.棧的實(shí)現(xiàn)
Stack<Integer> st = new Stack<Integer>();
st.push(1);
st.peek( )
st.pop();
st.empty();

4.創(chuàng)建hash表
List[] hashmap= new List[numCourses];
for(int i=0;i<numCourses;i++){
hashmap[i]=new ArrayList<Integer>();
}

5.String類
"abc".toCharArray()
"a b c".split(" ")
"abc ".substring(0,"abc ".length()-1)

6.Integer類
Integer.MIN_VALUE
Integer.MAX_VALUE
Integer.valueOf("123")

7.優(yōu)先隊(duì)列
Queue<Integer> integerPriorityQueue = new PriorityQueue<>(7);
queue.add(1);
queue.poll();

Queue<ListNode> integerPriorityQueue = new PriorityQueue<ListNode>(lists.length,(a,b) -> a.val-b.val);

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容