国产亚洲精品福利在线无卡一,国产精久久一区二区三区,亚洲精品无码国模,精品久久久久久无码专区不卡

當(dāng)前位置: 首頁 > news >正文

徐州做汽車銷售的公司網(wǎng)站企業(yè)網(wǎng)站建設(shè)平臺

徐州做汽車銷售的公司網(wǎng)站,企業(yè)網(wǎng)站建設(shè)平臺,重慶建筑網(wǎng)絡(luò)平臺,哪個跨境電商網(wǎng)站做的最好List不同實(shí)現(xiàn)類的對比 文章目錄 List不同實(shí)現(xiàn)類的對比實(shí)現(xiàn)類之一ArrayList實(shí)現(xiàn)類之二 LinkedList實(shí)現(xiàn)類之三 Vector練習(xí) java.util.Collection用于存儲一個一個數(shù)據(jù)的框架子接口:List存儲有序的、可重復(fù)的數(shù)據(jù)(相當(dāng)于動態(tài)數(shù)組) ArrayList lis…

List不同實(shí)現(xiàn)類的對比

文章目錄

  • List不同實(shí)現(xiàn)類的對比
    • 實(shí)現(xiàn)類之一`ArrayList`
    • 實(shí)現(xiàn)類之二 `LinkedList`
    • 實(shí)現(xiàn)類之三 `Vector`
    • 練習(xí)

  • java.util.Collection用于存儲一個一個數(shù)據(jù)的框架
  • 子接口:List存儲有序的、可重復(fù)的數(shù)據(jù)(相當(dāng)于動態(tài)數(shù)組)
    • ArrayList list的主要實(shí)現(xiàn)類(線程不安全、效率高) 底層使用Object[]的數(shù)組存儲。添加數(shù)據(jù)、查找數(shù)據(jù)時,效率較高;插入數(shù)據(jù)、刪除數(shù)據(jù)時,效率較低
    • Vector List的古老實(shí)現(xiàn)類 (線程安全、效率低) 底層使用Object[]數(shù)組存儲
    • LinkedList 底層使用雙向鏈表的方式進(jìn)行存儲。插入數(shù)據(jù)、刪除數(shù)據(jù)時效率較高;添加數(shù)據(jù)、查找數(shù)據(jù)時,效率較低。

實(shí)現(xiàn)類之一ArrayList

  • ArrayList 是 List 接口的主要實(shí)現(xiàn)類

  • 本質(zhì)上,ArrayList是對象引用的一個”變長”數(shù)組

  • Arrays.asList(…) 方法返回的 List 集合,既不是 ArrayList 實(shí)例,也不是 Vector 實(shí)例。 Arrays.asList(…) 返回值是一個固定長度的 List 集合

實(shí)現(xiàn)類之二 LinkedList

對于頻繁的插入或刪除元素的操作,建議使用LinkedList類,效率較高。這是由底層采用鏈表(雙向鏈表)結(jié)構(gòu)存儲數(shù)據(jù)決定的。

特有方法:

  • void addFirst(Object obj)
  • void addLast(Object obj)
  • Object getFirst()
  • Object getLast()
  • Object removeFirst()
  • Object removeLast()

實(shí)現(xiàn)類之三 Vector

  • Vector 是一個古老的集合,JDK1.0就有了。大多數(shù)操作與ArrayList相同,區(qū)別之處在于Vector是線程安全的。
  • 在各種List中,最好把ArrayList作為默認(rèn)選擇。當(dāng)插入、刪除頻繁時,使用LinkedList;Vector總是比ArrayList慢,所以盡量避免使用。
  • 特有方法:
    • void addElement(Object obj)
    • void insertElementAt(Object obj,int index)
    • void setElementAt(Object obj,int index)
    • void removeElement(Object obj)
    • void removeAllElements()

練習(xí)

鍵盤錄入學(xué)生信息,保存到集合List中

  • 定義學(xué)生類。存在姓名、年齡的屬性
  • 使用ArrayList集合,保存錄入的多個學(xué)生對象
  • 循環(huán)錄入方式
  • 錄入結(jié)束后,用迭代器遍歷
//學(xué)生類
public class Student {private String name;private int age;public Student(String name, int age) {this.name = name;this.age = age;}public Student(){}public String getName() {return name;}public void setName(String name) {this.name = name;}public int getAge() {return age;}public void setAge(int age) {this.age = age;}@Overridepublic String toString() {return "Student{" +"name='" + name + '\'' +", age=" + age +'}';}@Overridepublic boolean equals(Object o) {if (this == o) return true;if (o == null || getClass() != o.getClass()) return false;Student student = (Student) o;return age == student.age && Objects.equals(name, student.name);}@Overridepublic int hashCode() {return Objects.hash(name, age);}
}
//Test類
import java.util.ArrayList;
import java.util.Scanner;public class StudentTest {public static void main(String[] args) {Scanner input = new Scanner(System.in);ArrayList list = new ArrayList();System.out.println("請錄入學(xué)生信息:");while(true){System.out.println("1,繼續(xù)錄入  0.結(jié)束錄入");int selection = input.nextInt();if(selection == 0){break;}System.out.println("請輸入學(xué)生的姓名:");String name = input.next();System.out.println("請輸入學(xué)生的年齡");int age = input.nextInt();Student s = new Student(name,age);list.add(s);}//遍歷集合中的學(xué)生信息System.out.println("遍歷學(xué)生信息");for(Object s : list){System.out.println(s.toString());}input.close();}
}
http://m.aloenet.com.cn/news/38828.html

相關(guān)文章:

  • iis一個文件夾配置多個網(wǎng)站成都排名seo公司
  • 做網(wǎng)站公司漢獅網(wǎng)絡(luò)開封網(wǎng)站設(shè)計(jì)
  • 射洪哪里可以做網(wǎng)站北京seo推廣外包
  • 寧波營銷型網(wǎng)站建設(shè)網(wǎng)絡(luò)銷售平臺有哪些
  • 新風(fēng)格網(wǎng)站灰色詞排名代做
  • 上海工商登記查詢系統(tǒng)南昌網(wǎng)站優(yōu)化公司
  • 順德公益網(wǎng)站制作seo網(wǎng)站推廣
  • 去年做的電子請?zhí)趺凑以W(wǎng)站百度的網(wǎng)頁地址
  • 網(wǎng)站建設(shè)咨詢公企業(yè)網(wǎng)站建設(shè)門戶
  • 網(wǎng)站定位策劃小紅書關(guān)鍵詞優(yōu)化
  • 佛山網(wǎng)站建設(shè)公司哪家性價比高百度競價代運(yùn)營托管
  • 西安市城鄉(xiāng)建設(shè)檔案館網(wǎng)站域名注冊網(wǎng)站
  • 核名查詢系統(tǒng)seo如何優(yōu)化
  • 網(wǎng)站開發(fā)計(jì)劃書模板淘寶引流推廣平臺
  • 如何進(jìn)行優(yōu)化霸屏seo服務(wù)
  • 企業(yè)站用什么程序做網(wǎng)站友情鏈接樣式
  • 大連市營商環(huán)境建設(shè)局網(wǎng)站網(wǎng)絡(luò)銷售平臺上市公司有哪些
  • 網(wǎng)站二級域名怎么設(shè)置小紅書關(guān)鍵詞搜索量查詢
  • 桂林網(wǎng)站建設(shè)內(nèi)容瀏覽器2345網(wǎng)址導(dǎo)航下載安裝
  • 馬云將來淘汰的十個行業(yè)網(wǎng)站建設(shè)網(wǎng)站如何添加友情鏈接
  • 做網(wǎng)站與網(wǎng)店運(yùn)營如何免費(fèi)創(chuàng)建自己的網(wǎng)站平臺
  • wordpress活動召集插件seo內(nèi)部優(yōu)化具體做什么
  • 學(xué)做網(wǎng)站書籍微商營銷
  • 軟件app研發(fā)seo優(yōu)化標(biāo)題 關(guān)鍵詞
  • 怎么做網(wǎng)站后臺 更新日志網(wǎng)絡(luò)市場調(diào)研的方法
  • 網(wǎng)站偽靜態(tài)怎么設(shè)置seowhy官網(wǎng)
  • 網(wǎng)站仿做軟件seo是什么意思職業(yè)
  • 建設(shè)工程招標(biāo)網(wǎng)站互聯(lián)網(wǎng)推廣運(yùn)營是做什么的
  • 廣東出現(xiàn)新病毒是真的嗎關(guān)鍵詞優(yōu)化方法有什么步驟
  • 上海 做網(wǎng)站線下推廣方法有哪些