Java常用用法(數組、列表、集合間的轉換)Part01

1、數組轉list
	Arrays.asList(String[])
1、數組轉set
	new HashSet<>(Arrays.asList(String[]))
2、set轉數組
	 set.toArray(new String[set.size()])
3、Arrays.asList()
	轉出來的是個List<T>, 可以直接傳入字符串
new ArrrayList<>();
4、ArrayList轉數組
 list.toArray(new String[list.size()])

輸出2的16次方

public class N {
    public static void main(String[] args) {
        BigInteger bigInteger = new BigInteger("2");
        BigInteger pow = bigInteger.pow(16);
        System.out.println(pow);
        System.out.println(pow.divide(new BigInteger("2")));
    }
}

靜態方法中讀取配置文件

 InputStream in = MailUtil.class.getClassLoader().getResourceAsStream(fileName);  
 ClassLoader類加載器:將java文件加載到jvm中

獲取類加載器:類名.class.getClassLoader()

 ClassLoader classLoader = FileUtil.class.getClassLoader();
/**
 getResource()方法會去classpath下找這個文件,獲取到url resource, 得到這個資源後,調用url.getFile獲取到 文件 的絕對路徑
 */
URL url = classLoader.getResource(fileName);
/**
 * url.getFile() 得到這個文件的絕對路徑
 */
File file = new File(url.getFile());

clone

基本類型直接複製,引用類型需要實現Cloneable 調用super.clone() 

數組、list、set間轉換
java輸出2的n次方
java中String和char
靜態方法中讀取配置文件的解決方案(補充:類加載器)
clone()詳解

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章