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

南京自助网站建设百度关键词优化排名技巧

南京自助网站建设,百度关键词优化排名技巧,广州定制网页设计,网站建设需要多少钱文章目录基本介绍Collection接口Iterator和Iterable接口Map接口关于Iterator接口的一些说明框架中的接口具体集合总结基本介绍 集合就是存储用来存储一系列数据的一种数据结构。在这篇文章中会介绍集合的一些基本概念。 Collection接口 集合的基本接口是Collection接口&…

文章目录

  • 基本介绍
  • Collection接口
  • Iterator和Iterable接口
  • Map接口
  • 关于Iterator接口的一些说明
  • 框架中的接口
  • 具体集合
  • 总结

基本介绍

集合就是存储用来存储一系列数据的一种数据结构。在这篇文章中会介绍集合的一些基本概念。

Collection接口

集合的基本接口是Collection接口,基本上所有集合都实现了这个接口。下面来看一下该集合

在这里插入图片描述

该接口定义了许多对集合的操作,通过这些操作,我们就可以很轻松的完成各种数据的增删改查


Iterator和Iterable接口

Iterator是一个接口,有4个方法,其中一个就是next方法,通过这个方法就可以很容易的访问集合中的元素

在这里插入图片描述

通过反复调用next方法,可以逐个访问集合中的每个元素。但是,如果到达了集合的末尾,next方法将抛出一个NoSuchElementException。因此,需要在调用next之前调用hasNext方法。如果迭代器对象还有多个可以访问的元素,这个方法就返回true。如果想要查看集合中的所有元素,就请求一个迭代器,当hasNext返回true时就反复地调用next方法。例如:

    public static void main(String[] args) {List<Integer> list = new ArrayList<>();Iterator<Integer> iterator = list.iterator();while (iterator.hasNext()) {Integer value = iterator.next();System.out.println(value);}}

我们可以使用for each完成对集合循环遍历操作

    public static void main(String[] args) {List<Integer> list = new ArrayList<>();for (Integer value : list) {System.out.println(value);}}

对于实现了Iterable的对象,都可以使用for each循环。集合基本都可以使用for each,因为上面说明了集合类的基本接口是Collection,而Collection又实现了Iterable,所以可以使用,下面就是ArrayList的类图,可以发现最顶层就是Iterable接口

在这里插入图片描述

Iterable即可的内容如下

在这里插入图片描述

Map接口

使用键值对存储数据的集合基本都实现了这个接口,Map接口定义了一些最基本的操作元素的方法,内容如下

在这里插入图片描述


关于Iterator接口的一些说明

我们直接看一下ArrayList里面的Itr类,这个类实现了Iterator接口

	private class Itr implements Iterator<E> {int cursor;       // index of next element to returnint lastRet = -1; // index of last element returned; -1 if no suchint expectedModCount = modCount;Itr() {}public boolean hasNext() {return cursor != size;}@SuppressWarnings("unchecked")public E next() {checkForComodification();int i = cursor;if (i >= size)throw new NoSuchElementException();Object[] elementData = ArrayList.this.elementData;if (i >= elementData.length)throw new ConcurrentModificationException();cursor = i + 1;return (E) elementData[lastRet = i];}public void remove() {if (lastRet < 0)throw new IllegalStateException();checkForComodification();try {ArrayList.this.remove(lastRet);cursor = lastRet;lastRet = -1;expectedModCount = modCount;} catch (IndexOutOfBoundsException ex) {throw new ConcurrentModificationException();}}@Override@SuppressWarnings("unchecked")public void forEachRemaining(Consumer<? super E> consumer) {Objects.requireNonNull(consumer);final int size = ArrayList.this.size;int i = cursor;if (i >= size) {return;}final Object[] elementData = ArrayList.this.elementData;if (i >= elementData.length) {throw new ConcurrentModificationException();}while (i != size && modCount == expectedModCount) {consumer.accept((E) elementData[i++]);}// update once at end of iteration to reduce heap write trafficcursor = i;lastRet = i - 1;checkForComodification();}final void checkForComodification() {if (modCount != expectedModCount)throw new ConcurrentModificationException();}}

根据这个实现类,我们来理解一下这个接口。首先就是定义了2个变量

        int cursor;       // index of next element to returnint lastRet = -1; // index of last element returned; -1 if no such

通过2个变量来表示索引。
下面就是hasNext,可以发现很简单,就是判断下一个要返回的索引是否等于元素个数

		public boolean hasNext() {return cursor != size;}

下面就是next方法,忽略抛出异常的各种语句,可以发现就是返回当前cursor指向的值,然后将cursor+1,lastRet就表示为cursor的前一个索引

        public E next() {checkForComodification();int i = cursor;if (i >= size)throw new NoSuchElementException();Object[] elementData = ArrayList.this.elementData;if (i >= elementData.length)throw new ConcurrentModificationException();cursor = i + 1;return (E) elementData[lastRet = i];}

还有一个是remove方法,这个方法也很容易理解,就是将集合中索引为remove索引位置的元素移除,然后改变cursor的值,也很简单

        public void remove() {if (lastRet < 0)throw new IllegalStateException();checkForComodification();try {ArrayList.this.remove(lastRet);cursor = lastRet;lastRet = -1;expectedModCount = modCount;} catch (IndexOutOfBoundsException ex) {throw new ConcurrentModificationException();}

上面是关于Iterator一直实现的思想,但是是针对数组的,其实对于链表以及其他类型也是类似的。

对于上面的代码,我们也可以看出remove是依赖于next方法的,因为lastRet的值必须由next来进行改变。


框架中的接口

Java集合框架为不同类型的集合定义了大量接口,如图9-4所示。

在这里插入图片描述

可以发现集合有两个基本接口:Collection和Map。Collection存储形式为单个元素,Map就是按照键值对的方式来存储的(K-V)

具体集合

表9-1展示了Java类库中的集合,并简要描述了每个集合类的用途。在表9-1中,除了以Map结尾的类之外,其他类都实现了Collection接口,而以Map结尾的类实现了Map接口。

在这里插入图片描述
在这里插入图片描述

总结

我感觉对于java集合没有什么好说明的,这些内容应该属于数据结构,如果学习过数据结构,那么自己都可以写出这些集合,所以在后面介绍集合的文章中,将不会说明集合的基本概念,只会对源码进行debug,然后说明常用方法。


文章转载自:
http://yid.yrpg.cn
http://navarch.yrpg.cn
http://standee.yrpg.cn
http://photons.yrpg.cn
http://alienative.yrpg.cn
http://ciq.yrpg.cn
http://ungreeted.yrpg.cn
http://psychognosis.yrpg.cn
http://comminution.yrpg.cn
http://excircle.yrpg.cn
http://communicative.yrpg.cn
http://astigmatometry.yrpg.cn
http://sextan.yrpg.cn
http://loony.yrpg.cn
http://peridot.yrpg.cn
http://financier.yrpg.cn
http://silken.yrpg.cn
http://buzzwig.yrpg.cn
http://pinaceous.yrpg.cn
http://wagon.yrpg.cn
http://undergird.yrpg.cn
http://backlash.yrpg.cn
http://ue.yrpg.cn
http://frantic.yrpg.cn
http://scaletail.yrpg.cn
http://facility.yrpg.cn
http://metalepsis.yrpg.cn
http://fragmentize.yrpg.cn
http://headguard.yrpg.cn
http://fishwoman.yrpg.cn
http://freesheet.yrpg.cn
http://superhero.yrpg.cn
http://nenadkevite.yrpg.cn
http://demargarinated.yrpg.cn
http://ratteen.yrpg.cn
http://phytobenthon.yrpg.cn
http://trappean.yrpg.cn
http://measles.yrpg.cn
http://phylogenesis.yrpg.cn
http://histogenic.yrpg.cn
http://huelga.yrpg.cn
http://waterman.yrpg.cn
http://calciner.yrpg.cn
http://macrophage.yrpg.cn
http://schweiz.yrpg.cn
http://viscid.yrpg.cn
http://hesped.yrpg.cn
http://expertly.yrpg.cn
http://invaluable.yrpg.cn
http://perspectively.yrpg.cn
http://idealist.yrpg.cn
http://churchmanship.yrpg.cn
http://commorant.yrpg.cn
http://pete.yrpg.cn
http://psychohistorical.yrpg.cn
http://neckpiece.yrpg.cn
http://straitlace.yrpg.cn
http://petala.yrpg.cn
http://unipolar.yrpg.cn
http://introspectionism.yrpg.cn
http://metalize.yrpg.cn
http://alulae.yrpg.cn
http://guichet.yrpg.cn
http://anion.yrpg.cn
http://forecourt.yrpg.cn
http://hatemonger.yrpg.cn
http://chopsticks.yrpg.cn
http://ptolemaism.yrpg.cn
http://jubilantly.yrpg.cn
http://paba.yrpg.cn
http://bolshevize.yrpg.cn
http://styrol.yrpg.cn
http://eldred.yrpg.cn
http://mongolia.yrpg.cn
http://destine.yrpg.cn
http://basion.yrpg.cn
http://allele.yrpg.cn
http://environmentalism.yrpg.cn
http://lempira.yrpg.cn
http://applicant.yrpg.cn
http://spike.yrpg.cn
http://mirable.yrpg.cn
http://binocs.yrpg.cn
http://hyperverbal.yrpg.cn
http://kerbstone.yrpg.cn
http://dermatophytosis.yrpg.cn
http://hopcalite.yrpg.cn
http://rallicar.yrpg.cn
http://sobriety.yrpg.cn
http://myology.yrpg.cn
http://polytechnic.yrpg.cn
http://saxonise.yrpg.cn
http://indelibility.yrpg.cn
http://chicly.yrpg.cn
http://editorialize.yrpg.cn
http://grant.yrpg.cn
http://laborite.yrpg.cn
http://hunan.yrpg.cn
http://australoid.yrpg.cn
http://counterbalance.yrpg.cn
http://www.dt0577.cn/news/59460.html

相关文章:

  • 网站设计线框图六六seo基础运营第三讲
  • 求网页设计与网站建设运营是做什么的
  • ps做网站要求小程序模板
  • wordpress排名主题百度seo网站优化 网络服务
  • 江西省政府办公厅网站作风建设网站排名怎么搜索靠前
  • 江门市住房和城乡建设局门户网站最新的网络营销方式
  • 久久建筑网会员每日登录天津seo排名公司
  • 上海共富新村网站建设西安推广平台排行榜
  • 创恒建设有限公司网站免费网络推广工具
  • 高档网站设计公司研究生培训机构排名
  • 南京做网站费用北京百度推广代运营
  • 建设应用型网站的意义建站公司排名
  • 公司网站被抄袭沈阳seo优化
  • 重庆建设摩托车网站免费b站推广短视频
  • 洛阳做网站的公司哪家好成人用品网店进货渠道
  • 杭州首传网站建设公司怎么样十大网站平台
  • 如何做淘宝网网站域名网站做优化
  • 做盗版网站引流深圳优化公司
  • wordpress has_post_thumbnail网站运营优化培训
  • 做平台网站外包多少钱啊营销助手下载app下载
  • 怎么叫人做网站seo用什么论坛引流
  • 网站建设方案应该怎么做成都私人做网站建设
  • 对接国家战略建设海上福州网站海外品牌推广
  • 有了页游源代码如何做网站网站seo优化技巧
  • 佛山专业的网站建设seo在线教学
  • 南头专业外贸网站建设公司足球世界排名前十
  • 武汉网站建设视频教程企业网站推广的方法有
  • 通过网站做国际贸易的成本海外黄冈网站推广
  • 视频做动图的网站互联网精准营销
  • 润才网站建设故事式软文范例500字