LeetCode刷题中遇到的一些知识点
生活随笔
收集整理的這篇文章主要介紹了
LeetCode刷题中遇到的一些知识点
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
char 數組與Sting 相互轉換
String s; char array[]=s.toCharArray(); s=String.vauleOf(array); 或者 new String(array)HashMap 與HashSet
hashMap 是key-value
hashSet 是key
通過hashcode進行選擇bucket 然后判斷equal()是否相等來決定是否加入
http://www.importnew.com/6931.html
http://www.importnew.com/21841.html
hashmap 深入拷問:http://www.importnew.com/7099.html
hashmap hashtable區別http://www.importnew.com/7010.html
hashSet 使用方法:
使用工具類==Arrays.asList()==把數組轉換成集合時,不能使用其修改集合相關的方法,它的add/remove/clear方法會拋出UnsupportOperationException異常
Integer[] data = {1,2,3,4,5}; List list = Arrays.asList(data); ------------------------------------ private final static HashSet<Character> vowels=new HashSet<>(Arrays.asList('a','e','i','o','u','A','E','I','O','U'));java List接口實現類
首先看這兩類都實現List接口,而List接口一共有三個實現類,分別是ArrayList、Vector和LinkedList。List用于存放多個元素,能夠維護元素的次序,并且允許元素的重復。3個具體實現類的相關區別如下:
查看Java源代碼,發現當數組的大小不夠的時候,需要重新建立數組,然后將元素拷貝到新的數組內,ArrayList和Vector的擴展數組的大小不同。
List中ArrayList 超全使用攻略:
https://blog.csdn.net/qq_33505051/article/details/78967362 String ar[]= {"dsds","sdfs","sdd"}; List<String>vv=new ArrayList<String>(Arrays.asList(ar)); Integer am[]= {1,2,3}; List <Integer>ccc=new ArrayList<Integer>(Arrays.asList(am));記住List引入的包是import java.util.List;中的。
總結
以上是生活随笔為你收集整理的LeetCode刷题中遇到的一些知识点的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: numpy and pandas
- 下一篇: 量子计算知识积累