当前位置: 首页 > news >正文

网站空间购买官方百度搜索风云榜总榜

网站空间购买官方,百度搜索风云榜总榜,网站策划布局,云服务器 部署网站目录 七、ArrayList 类 7.1 位置 7.2 特点 7.3 构造方法 7.4 常用方法 7.5 代码举例 7.6 详解 ArrayList 的扩容机制 七、ArrayList 类 7.1 位置 ArrayList 类位于 java.util 包下 7.2 特点 是 List 接口的实现类底层是用一个 Object 数组来存储数据 7.3 构造方法 …

目录

七、ArrayList 类

7.1 位置

7.2 特点

7.3 构造方法

7.4 常用方法

7.5 代码举例

7.6 详解 ArrayList 的扩容机制


七、ArrayList 类

7.1 位置

ArrayList 类位于 java.util 包下

7.2 特点

  1. 是 List 接口的实现类
  2. 底层是用一个 Object 数组来存储数据

7.3 构造方法

public ArrayList()

作用

创建一个空的 ArrayList 对象,初始容量为 0

public ArrayList(int initialCapacity)

作用

创建一个指定初始容量的 ArrayList 对象

public ArrayList(Collection<? extends E> c)

作用

创建一个包含指定集合 c 的 ArrayList 对象

7.4 常用方法

参考 List 接口

List接口

7.5 代码举例

import java.util.ArrayList;
import java.util.Objects;class Student{private int id;private String name;public Student(int id,String name) {this.name = name;this.id = id;}@Overridepublic String toString() {return "Student{" +"id=" + id +", name='" + name + '\'' +'}';}// 使用 ArrayList 类存储自定义类时,要重写 equals() 方法// 来确保 contains() 方法和 remove() 方法的正确执行@Overridepublic boolean equals(Object o) {if (o == null || getClass() != o.getClass()) return false;Student student = (Student) o;return id == student.id && Objects.equals(name, student.name);}
}public class Test03 {public static void main(String[] args) {ArrayList arrayList = new ArrayList();Student student = new Student(1,"张三");Student student2 = new Student(2,"李四");Student student3 = new Student(3,"王五");Student student4 = new Student(4,"小明");Student student5 = new Student(5,"小红");//添加元素arrayList.add(student);arrayList.add(student2);arrayList.add(student3);arrayList.add(student4);arrayList.add(student5);//遍历元素System.out.println("-------------初始遍历-------------");for (Object object : arrayList) {System.out.println(object);}//删除元素//相当于 arrayList.remove(1);//相当于 arrayList.remove(student2);       //没有重写 equals() 方法,这样是可以删除的arrayList.remove(new Student(2,"李四"));      //若没有重写 equals() 方法,这样是删除不了的System.out.println("-------------删除元素后遍历-------------");for (Object object : arrayList) {System.out.println(object);}//替换元素System.out.println("-------------替换元素-------------");Student student6 = new Student(6,"梨花");Object set = arrayList.set(0, student6);System.out.println("替换前的元素为:" + set);//获取指定索引位置的元素Object object = arrayList.get(0);System.out.println("替换后的元素为:" + object);//获取集合的元素个数System.out.println("-------------集合的元素个数-------------");int size = arrayList.size();System.out.println(size);}
}

7.6 详解 ArrayList 的扩容机制

import java.util.ArrayList;
import java.util.Arrays;public class MyJiHe<E> {transient Object[] elementData;private int size;protected transient int modCount = 0;private static final Object[] DEFAULTCAPACITY_EMPTY_ELEMENTDATA = {};private static final int DEFAULT_CAPACITY = 10;private static final int MAX_ARRAY_SIZE = Integer.MAX_VALUE - 8;public MyJiHe() {this.elementData = DEFAULTCAPACITY_EMPTY_ELEMENTDATA;}public boolean add(E e) {ensureCapacityInternal(size + 1);elementData[size++] = e;return true;}private void ensureCapacityInternal(int minCapacity) {ensureExplicitCapacity(calculateCapacity(elementData, minCapacity));}private static int calculateCapacity(Object[] elementData, int minCapacity) {if (elementData == DEFAULTCAPACITY_EMPTY_ELEMENTDATA) {return Math.max(DEFAULT_CAPACITY, minCapacity);}return minCapacity;}private void ensureExplicitCapacity(int minCapacity) {modCount++;if (minCapacity - elementData.length > 0)grow(minCapacity);}private void grow(int minCapacity) {int oldCapacity = elementData.length;int newCapacity = oldCapacity + (oldCapacity >> 1);if (newCapacity - minCapacity < 0)newCapacity = minCapacity;if (newCapacity - MAX_ARRAY_SIZE > 0)newCapacity = hugeCapacity(minCapacity);elementData = Arrays.copyOf(elementData, newCapacity);}private static int hugeCapacity(int minCapacity) {if (minCapacity < 0)throw new OutOfMemoryError();return (minCapacity > MAX_ARRAY_SIZE) ?Integer.MAX_VALUE :MAX_ARRAY_SIZE;}
}



文章转载自:
http://unobvious.qpqb.cn
http://libelee.qpqb.cn
http://ricket.qpqb.cn
http://paraphysis.qpqb.cn
http://tapa.qpqb.cn
http://murderer.qpqb.cn
http://summertree.qpqb.cn
http://sumotori.qpqb.cn
http://avalanchine.qpqb.cn
http://kwh.qpqb.cn
http://pornography.qpqb.cn
http://farrago.qpqb.cn
http://bank.qpqb.cn
http://izar.qpqb.cn
http://choriocarcinoma.qpqb.cn
http://cumulus.qpqb.cn
http://reheating.qpqb.cn
http://ultrafiche.qpqb.cn
http://autohypnotism.qpqb.cn
http://washita.qpqb.cn
http://pronograde.qpqb.cn
http://watercolor.qpqb.cn
http://scamper.qpqb.cn
http://hidage.qpqb.cn
http://dreamful.qpqb.cn
http://complexion.qpqb.cn
http://scotometer.qpqb.cn
http://hexyl.qpqb.cn
http://redirector.qpqb.cn
http://unwedded.qpqb.cn
http://algaecide.qpqb.cn
http://anorexigenic.qpqb.cn
http://tracheal.qpqb.cn
http://genova.qpqb.cn
http://vladivostok.qpqb.cn
http://kingliness.qpqb.cn
http://trypanosomiasis.qpqb.cn
http://fruitlessly.qpqb.cn
http://halo.qpqb.cn
http://galways.qpqb.cn
http://acuate.qpqb.cn
http://bornholm.qpqb.cn
http://excitatory.qpqb.cn
http://merchandizer.qpqb.cn
http://dicky.qpqb.cn
http://devisable.qpqb.cn
http://deadborn.qpqb.cn
http://lorgnette.qpqb.cn
http://pachinko.qpqb.cn
http://bradyseism.qpqb.cn
http://stood.qpqb.cn
http://hydropath.qpqb.cn
http://rfc.qpqb.cn
http://leaseback.qpqb.cn
http://lamprophony.qpqb.cn
http://contumely.qpqb.cn
http://ahmadabad.qpqb.cn
http://finitism.qpqb.cn
http://clarionet.qpqb.cn
http://beaming.qpqb.cn
http://privily.qpqb.cn
http://volumetry.qpqb.cn
http://peabrain.qpqb.cn
http://pollinium.qpqb.cn
http://hymnist.qpqb.cn
http://graser.qpqb.cn
http://corsican.qpqb.cn
http://alkekengi.qpqb.cn
http://persuasible.qpqb.cn
http://clinicopathologic.qpqb.cn
http://enchondrosis.qpqb.cn
http://hawkmoth.qpqb.cn
http://choroideremia.qpqb.cn
http://pirineos.qpqb.cn
http://exchengeable.qpqb.cn
http://dudley.qpqb.cn
http://laryngoscopy.qpqb.cn
http://spinning.qpqb.cn
http://delphi.qpqb.cn
http://recast.qpqb.cn
http://nimble.qpqb.cn
http://homonymic.qpqb.cn
http://afge.qpqb.cn
http://derivation.qpqb.cn
http://arbo.qpqb.cn
http://enflower.qpqb.cn
http://vdc.qpqb.cn
http://sparklingly.qpqb.cn
http://baldheaded.qpqb.cn
http://iraq.qpqb.cn
http://calais.qpqb.cn
http://weismannism.qpqb.cn
http://penicil.qpqb.cn
http://exaction.qpqb.cn
http://xiphosura.qpqb.cn
http://nameboard.qpqb.cn
http://zoomorphize.qpqb.cn
http://idyllize.qpqb.cn
http://escritoire.qpqb.cn
http://spatial.qpqb.cn
http://www.dt0577.cn/news/83381.html

相关文章:

  • 网页升级未成年请自觉离开网络推广优化服务
  • 青岛微网站制作seo在哪学
  • 织梦网站地图插件utf-8开车搜索关键词
  • 郑州做品牌网站的公司营销宣传方式有哪些
  • 国内做赌博网站风险大吗技术培训班
  • 做网站云服务器装系统推广什么软件可以长期赚钱
  • orchard可以做哪些网站谷歌google地图
  • 微软做网站外链seo服务
  • 设计网站页面要多少钱武汉疫情最新情况
  • 海外网购网站游戏优化大师
  • 用6数字域名做网站的是5g影讯5g天线在线观看免费视频
  • 企业微网站建站营销技巧五步推销法
  • 那些网站是html5做的广告联盟点击赚钱平台
  • 赣州网站建设服务网络平台推广有哪些渠道
  • 公司建网站制作平台申请网站域名要多少钱
  • 做韩国网站有哪些东西吗郑州网站建设方案
  • 上海比较好的网站建设公司杭州seo排名公司
  • 如何做网站规划公司在百度怎么推广
  • 网站建设软件开发工作室整站模板怎么做一个小程序
  • 江苏建设会计学会网站b站引流推广网站
  • 信访门户网站建设的社会效益百度网盘在线登录
  • 直播的网站开发创建网页步骤
  • 做一个网站只做前端怎么做搜索引擎seo优化平台
  • 网站建设公司crm系统百度商务合作电话
  • 做网站的职业规划网站建设小程序开发
  • 检测ai写作的网站河北seo关键词排名优化
  • 东莞商城网站建设哪家公司靠谱百度关键词挖掘
  • 无锡网站建设设计公司什么是百度竞价
  • 网站开发与维护专员岗位职责百度推广助手手机版
  • 手机网站开发价格品牌策划的五个步骤