日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【ArrayList集合】

發(fā)布時間:2024/1/18 编程问答 25 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【ArrayList集合】 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

1.ArrayList

1.1ArrayList類概述

  • 什么是集合

    ? 提供一種存儲空間可變的存儲模型,存儲的數(shù)據(jù)容量可以發(fā)生改變

  • ArrayList集合的特點

    ? 底層是數(shù)組實現(xiàn)的,長度可以變化

  • 泛型的使用

    ? 用于約束集合中存儲元素的數(shù)據(jù)類型

1.2ArrayList類常用方法

1.2.1構(gòu)造方法

方法名說明
public ArrayList()創(chuàng)建一個空的集合對象

1.2.2成員方法

方法名說明
public boolean remove(Object o)刪除指定的元素,返回刪除是否成功
public E remove(int index)刪除指定索引處的元素,返回被刪除的元素
public E set(int index,E element)修改指定索引處的元素,返回被修改的元素
public E get(int index)返回指定索引處的元素
public int size()返回集合中的元素的個數(shù)
public boolean add(E e)將指定的元素追加到此集合的末尾
public void add(int index,E element)在此集合中的指定位置插入指定的元素

1.2.3示例代碼

public class ArrayListDemo02 {public static void main(String[] args) {//創(chuàng)建集合ArrayList<String> array = new ArrayList<String>();//添加元素array.add("hello");array.add("world");array.add("java");//public boolean remove(Object o):刪除指定的元素,返回刪除是否成功 // System.out.println(array.remove("world")); // System.out.println(array.remove("javaee"));//public E remove(int index):刪除指定索引處的元素,返回被刪除的元素 // System.out.println(array.remove(1));//IndexOutOfBoundsException // System.out.println(array.remove(3));//public E set(int index,E element):修改指定索引處的元素,返回被修改的元素 // System.out.println(array.set(1,"javaee"));//IndexOutOfBoundsException // System.out.println(array.set(3,"javaee"));//public E get(int index):返回指定索引處的元素 // System.out.println(array.get(0)); // System.out.println(array.get(1)); // System.out.println(array.get(2));//System.out.println(array.get(3)); //ArrayIndexOutOfBoundsException 索引越界//public int size():返回集合中的元素的個數(shù)System.out.println(array.size());//輸出集合System.out.println("array:" + array);} }

總結(jié)

以上是生活随笔為你收集整理的【ArrayList集合】的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。