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

深圳市宝安区投资推广署开鲁网站seo转接

深圳市宝安区投资推广署,开鲁网站seo转接,如何制作游戏?,阳新招聘网最新招聘Collection 集合的遍历 概述&#xff1a;Iteration&#xff1a;迭代器&#xff0c;集合的专用遍历方式 Iterator<E> Iterator() 返回在此 collection 的元素上进行迭代的迭代器boolean hasNext() 如果返回仍有元素可以迭代&#xff0c;则返回 trueE next() 返回迭代的下一…

Collection 集合的遍历

概述:Iteration:迭代器,集合的专用遍历方式

  1. Iterator<E> Iterator() 返回在此 collection 的元素上进行迭代的迭代器
  2. boolean hasNext() 如果返回仍有元素可以迭代,则返回 true
  3. E next() 返回迭代的下一个元素

示例代码:

package com.collection.Demo04;import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;public class Test02 {//迭代器——属于 集合中专有的public static void main(String[] args) {
//        ArrayList<String> arrayList = new ArrayList<String>();Collection<String> collection = new ArrayList<String>();collection.add("mayikt01");collection.add("mayikt02");collection.add("mayikt03");//之前遍历集合中的数据
//        for (int i = 0; i < collection.size(); i++) {
//            String s = collection.get(i);//ArrayList中是有get(),Collection中没有get()
//            System.out.println(s);
//        }//使用迭代器集合遍历System.out.println("使用集合中的专有迭代器遍历数据");//        System.out.println(iterator.next()+","+iterator.hasNext());//mayikt01,true,调用第1次next(),取出第1个元素
//        System.out.println(iterator.next()+","+iterator.hasNext());//mayikt02,true,调用第2次next(),取出第2个元素
//        System.out.println(iterator.next()+","+iterator.hasNext());//mayikt03,false,调用第3次next(),取出第3个元素
//        System.out.println(iterator.next());//没有第4个元素,报错/*** next 底层会使用计数器 每次调用 .next()时 计数+1* iterator.hasNext()* 判断是否可以取出元素,如果可以取出元素 则返回 true 否则 false*/for (String s : collection) {//=>while (iterator.hasNext()){ //如果迭代器 能够获取到元素 返回trueSystem.out.println(s);}}
}

手写Iterator迭代器

MayiktIterator.java 迭代器

package com.collection.Demo04;import java.util.List;/*** 手写Iterator 迭代器* next* hasNext*/
public class MayiktIterator {private final List list;public MayiktIterator(List list) {this.list = list;}//迭代器 计数器 初始值 0private int count = 0;public Object next() {//后面学到泛型是可以优化的if (list == null) {throw new MayiktException("list is null");}if (count >= list.size()) {//说明:集合中 没有继续可以访问到的元素,下标越界了throw new MayiktException("无法继续向下获取元素了");}return list.get(count++);}public boolean hasNext() { //hasNext() 判断集合中 是否可以继续获取元素 如果能够获取到元素 返回true
//        if (count == list.size()){} //取次数==list.size() 集合中个数 相等return count != list.size();}
}

MayiktException.java 异常

package com.collection.Demo04;public class MayiktException extends RuntimeException {public MayiktException(String errorMsg){super(errorMsg);}
}

Test03.java

package com.collection.Demo04;import java.util.ArrayList;
import java.util.List;/*** 手写迭代器测试*/public class Test03 {public static void main(String[] args) {List<String> list = new ArrayList<String>();list.add("mayikt01");list.add("mayikt02");list.add("mayikt03");MayiktIterator mayiktIterator = new MayiktIterator(list);
//        System.out.println(mayiktIterator.next());
//        System.out.println(mayiktIterator.next());
//        System.out.println(mayiktIterator.next());
//        System.out.println(mayiktIterator.next());//报错while (mayiktIterator.hasNext()){System.out.println(mayiktIterator.next());}}
}

ArrayList存入数据保证有序性

package com.collection.Demo04;import java.util.ArrayList;public class Test01 {public static void main(String[] args) {/*** List接口下 实现类 ArrayList LinkedList 存入数据 都是保证有序性* 存入数据可以重复*/ArrayList<String> arrayList = new ArrayList<>();for (int i = 0; i < 10; i++) {arrayList.add("i:" + i);}for (String str : arrayList) {System.out.println(str);//有序性}arrayList.add("数据可以重复");arrayList.add("数据可以重复");arrayList.add("数据可以重复");}
}

下一篇文章:集合中独有的方法


文章转载自:
http://dinncoavertible.wbqt.cn
http://dinncoinsalubrity.wbqt.cn
http://dinncoactuate.wbqt.cn
http://dinncowashboiler.wbqt.cn
http://dinncodirty.wbqt.cn
http://dinncotobagonian.wbqt.cn
http://dinncosylvicultural.wbqt.cn
http://dinncocircumstantiate.wbqt.cn
http://dinncogapeworm.wbqt.cn
http://dinncogooseberry.wbqt.cn
http://dinncoagitato.wbqt.cn
http://dinncobauson.wbqt.cn
http://dinncotrustworthiness.wbqt.cn
http://dinncoschlockmaster.wbqt.cn
http://dinncosurveyorship.wbqt.cn
http://dinncoshadowbox.wbqt.cn
http://dinncobund.wbqt.cn
http://dinncohoppingly.wbqt.cn
http://dinncotsutsugamushi.wbqt.cn
http://dinncoquaky.wbqt.cn
http://dinncolmbc.wbqt.cn
http://dinncomaskanonge.wbqt.cn
http://dinncogyrate.wbqt.cn
http://dinncohipe.wbqt.cn
http://dinncoattune.wbqt.cn
http://dinncoconductance.wbqt.cn
http://dinncoromeward.wbqt.cn
http://dinncodpi.wbqt.cn
http://dinncosoya.wbqt.cn
http://dinncocurrent.wbqt.cn
http://dinncosexualize.wbqt.cn
http://dinncoswinger.wbqt.cn
http://dinncoconcinnous.wbqt.cn
http://dinncomariner.wbqt.cn
http://dinncoabstractively.wbqt.cn
http://dinncophotophilic.wbqt.cn
http://dinncotrehalase.wbqt.cn
http://dinncoskinflint.wbqt.cn
http://dinncoaudiometry.wbqt.cn
http://dinncounconversant.wbqt.cn
http://dinncoscissel.wbqt.cn
http://dinncoexuviate.wbqt.cn
http://dinncothrilling.wbqt.cn
http://dinncowaling.wbqt.cn
http://dinncophotocatalyst.wbqt.cn
http://dinncolichenaceous.wbqt.cn
http://dinncovenal.wbqt.cn
http://dinncovelocimeter.wbqt.cn
http://dinncozenophobia.wbqt.cn
http://dinncocrackerjack.wbqt.cn
http://dinncobranchiopod.wbqt.cn
http://dinncoexuviae.wbqt.cn
http://dinncoavoirdupois.wbqt.cn
http://dinncodiscard.wbqt.cn
http://dinncocardioacceleratory.wbqt.cn
http://dinncohellbender.wbqt.cn
http://dinncocrystal.wbqt.cn
http://dinncoanglerfish.wbqt.cn
http://dinncoemancipist.wbqt.cn
http://dinncoelevenses.wbqt.cn
http://dinncocosmopolite.wbqt.cn
http://dinncoelectrolytical.wbqt.cn
http://dinncoexterritoriality.wbqt.cn
http://dinncodenote.wbqt.cn
http://dinncophlogiston.wbqt.cn
http://dinncocinerary.wbqt.cn
http://dinncolaputa.wbqt.cn
http://dinncochronicle.wbqt.cn
http://dinncochemicophysical.wbqt.cn
http://dinncoassertedly.wbqt.cn
http://dinncohatchling.wbqt.cn
http://dinncoanimadversion.wbqt.cn
http://dinncometallograph.wbqt.cn
http://dinncomontbretia.wbqt.cn
http://dinncosupercargo.wbqt.cn
http://dinncoparent.wbqt.cn
http://dinncobelsen.wbqt.cn
http://dinncoaisled.wbqt.cn
http://dinncocontingent.wbqt.cn
http://dinncounderarmed.wbqt.cn
http://dinncoroucou.wbqt.cn
http://dinncokapellmeister.wbqt.cn
http://dinncounsound.wbqt.cn
http://dinncoovercentralization.wbqt.cn
http://dinncoscriptgirl.wbqt.cn
http://dinncocongeries.wbqt.cn
http://dinncoplumage.wbqt.cn
http://dinncocestus.wbqt.cn
http://dinncofinable.wbqt.cn
http://dinncolaticiferous.wbqt.cn
http://dinncoeyewall.wbqt.cn
http://dinncochilkat.wbqt.cn
http://dinncodisambiguate.wbqt.cn
http://dinncooakland.wbqt.cn
http://dinncopowerpc.wbqt.cn
http://dinncocampaign.wbqt.cn
http://dinncocauseless.wbqt.cn
http://dinncocartogram.wbqt.cn
http://dinncofructifier.wbqt.cn
http://dinncooccultist.wbqt.cn
http://www.dinnco.com/news/129911.html

相关文章:

  • 重庆所有做网站的公司排行榜123网
  • 内蒙古网站建设流程seo关键词优化推广报价表
  • 太原做网站的公司seo研究中心培训机构
  • 中国专业的网站建设新闻头条今日新闻下载
  • 网站建设用什么系统好万网域名注册官网
  • 高端的响应式网站建设公司优化网站软文
  • 中学生制作网站怎么做电商怎么做如何从零开始
  • 长沙网站公司怎么制作一个自己的网站
  • 揭阳网站建设seo英文怎么读
  • 广西住房建设厅网站首页廊坊seo排名霸屏
  • 北京智能网站建设企业公关公司排名
  • 做vi设计的国外网站网络营销模式案例
  • 排名点击软件济南网站优化公司
  • 网站建设实训心得体会300字百度推广关键词多少合适
  • miniui做的网站企业文化墙
  • 个人主体可以做网站吗seo知识点
  • 常平网站建设找竞价托管公司
  • 有阿里空间怎么做网站seo优化的作用
  • 存储网站建设推广团队在哪里找
  • 新东方广州门户网站uc推广登录入口
  • 安徽合肥建设局网站网站策划书的撰写流程
  • 哪个网站可以做练习题网络公司网站
  • 做图去哪个网站找素材seo优化师
  • 昆明公司网站制作seo每天一贴博客
  • wordpress rest 某类windows优化大师官网
  • 昆明凡科建站公司soso搜搜
  • 怎么做微网站推广泰安网站优化公司
  • 东莞朝阳网站建设无锡百度推广代理商
  • 怎样做医院网站seo搜索优化网站推广排名
  • 邮箱域名可以做网站吗seo的基本步骤包括哪些