Java基礎總結

2021-08-02 07:15:15 字數 839 閱讀 8591

##jdk 1.8##

1. hashtable

hashtable hash = new hashtable<>();

1.key-value均不能為空,否則nullpointerexception。

2.put相同的key,value值替換,返回原value。

3.方法被synchronized修飾,保證執行緒安全,影響效率。

4.put流程:判斷是否為空,若不為空key-->hashcode-->index(value在鍊錶中的索引)。

5.繼承dictionary類

2.hashmap

map

map=

new hashmap<>();

1. key-value均能為空

2. 執行緒不安全

3. 繼承abstractmap類

3.hashtable與hashmap的區別

1.hashtable繼承自dictionary類,hashmap繼承自abstractmap

2.hashtable的key-value均不能為空,hashmap都可以。

3.hashtable執行緒安全,hashmap執行緒不安全。

4.concurrenthashmap

concurrenthashmap chm = new concurrenthashmap<>();

1. key-value均不能為空

2. 執行緒安全,鎖分離,put部分加鎖,get不受限制,併發首選

3. 繼承abstractmap類

java基礎總結

float 賦值時後邊加f 如 float ff 1.2f 靜態變數 宣告時前邊 static 如static int x 0 資料型別轉換 低精度可以直接轉換成高精度,高精度轉換成低精度 需要顯示型別轉換 int x 50 float y x 顯示轉換 int a int 45.23 foreac...

Java基礎總結

1.string的理解 string s hello world 宣告的內容 乙個指向物件的引用,名為 s 可以指向型別為string的任何物件,目前指向 hello world 這個string型別的物件 string string s 明了另外乙個只能指向string物件的引用,名為string...

Java 基礎總結

1 物件導向的三大特性?三大特性是 封裝 繼承 多型 封裝,也就是把客觀事物封裝成抽象的類,並且類可以把自己的資料和方法只讓可信的類或者物件操作,對不可信的進行資訊隱藏。封裝是物件導向的特徵之一,是物件和類概念的主要特性。簡單的說,乙個類就是乙個封裝了資料以及操作這些資料的 的邏輯實體。在乙個物件內...