java基礎彙總

2021-09-12 01:55:21 字數 4176 閱讀 8946

如果有誤和遺漏,歡迎小夥伴發郵件 [email protected] ,我會第一時間更正和完善

public

static

void

main

(string[

] args)};

string abc = a.

get(

"abc");

string string = a.

get(

"3")

; string string2 = a.

get(

"3l");

string string3 = a.

get(

3l);

system.out.

println

(string+

"/"+string+

"/"+string2+

"/"+string3)

;}

執行結果

null / null / null / rong
總結

獲取不存的在key不會exception

只有對應的key才能取出值;

map

> map =

newhashmap

<

>(1

);map

newmap =

newhashmap

<

>()

};map

newmap2 =

newhashmap

<

>()

};map

newmap3 =

newhashmap

<

>()

};map.

put(

"a",newmap)

;map.

put(

"a",newmap2)

;map.

get(

"a")

.putall

(newmap3)

;system.out.

println

(map)

;

執行結果

}
總結

如果key存在,put相同值會替換舊值

如果往key裡面填入別的值,必須先get(),在put();

/**

* 獲取當前毫秒數:system.currenttimemillis(); 而不是new date().gettime();

* 說明:如果想獲取更加精確的納秒級時間值,用system.nanotime。

* 在jdk8中,針對統計時間等場景,推薦使用instant類。

* */

public

class

demo1

/* 獲取 1-number之間的隨機數 */

private

static long getrandom

(integer number)

/* 獲取 uuid ; mysql資料庫當中獲取方式: select uuid(); */

private

static string getuuid32()

/* 時間戳轉換日期 */

private

static string timestemptodate

(long timestemp)

/* 日期轉換為時間戳 */

private

static long datetotimestemp

(string string)

catch

(parseexception e)

return date.

gettime()

;}/* 日期轉換為時間戳 */

private

static string getspecificdate

(int year ,

int month,

int day )

/* 比較2個時間大小 */

private

static boolean timecomparison

(string date1,string date2)

/* 比較2個時間大小 */

private

static boolean timecomparison2

(string date1,string date2)

}

// 此方法list的size固定,使用add方法拋unsupportedoperationexception異常

list

list1 = arrays.

aslist

("***"

,"yyy"

,"zzz");

list

list2 =

newarraylist

<

>

(arrays.

aslist

("***"

,"yyy"

,"zzz"))

;list

list3 =

newarraylist()

;list3.

add(

"***");

list3.

add(

"yyy");

list3.

add(

"zzz");

list

list4 =

newarraylist()

};

map

map1 =

newhashmap

<

>()

;map.

put(

"key1"

,"value1");

map.

put(

"key2"

,"value2");

map.

put(

"key3"

,"value3");

mapmap2 =

newhashmap

<

>()

};

public

inte***ce

time

extends

function

default string log()

default dayofweek getweek()

static

time

fun()

public

static

void

main

(string[

] args)

}

console

[2019-05-09t19:29:51.119, 2019-05-08t19:29:51.119, 4]
public

inte***ce

throwingfunction

exception

,u>

catch

(exception ex)};

}public

static

void

main

(string[

] args)";

optional.

ofnullable

(json)

.map

((jsonobject:

:parseobject)).

ifpresent

( system.out:

:println);}

}

// 生成 [0-n) 個不重複的隨機數

public

static arraylist getdiffno

(int n)

while

(bool[num]);

bool[num]

=true

; list.

add(num);}

return list;

}

java筆試題 java基礎 筆記彙總

1 關於容器 collection list linkedlist 非同步 arraylist 非同步,實現了可變大小的元素陣列 vector 同步 stack set 不允許有相同的元素 map hashtable 同步,實現乙個key value對映的雜湊表 hashmap 非同步,weakha...

基礎 Java記憶體和GC彙總

主要來自jvm 8 定義。執行時資料區生命週期一部分與jvm繫結,一部分與執行緒繫結 pc暫存器 與執行緒繫結。指向當前方法位址 非native 或未定義 native jvm棧 與執行緒繫結 堆 與jvm繫結。用來放new出來的例項 函式區與jvm繫結。用來儲存編譯後的中間 執行時常量池 與類繫結...

Java面試通關要點彙總集 基礎篇

封裝 將客觀事物抽象成類,從而達到對資料的控制。那些資訊可開放給外部,那些資訊只允許自己使用 繼承 子類可以使用父類所有的功能,並且可以在不改變父類的基礎上進行功能擴充套件。多型 多型的實現是通過重寫來實現,當子類重寫父類的方法後,父類指標根據不同子類賦給它的指標,動態呼叫子類的方法。2.final...