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

织梦网站建设后优化步骤百度推广一年要多少钱

织梦网站建设后优化步骤,百度推广一年要多少钱,wordpress博客页面模板,网站建设公司固定ip目录 引言 一、Collection接口 1.1 主要方法 1.1.1 添加元素 1.1.2 删除元素 1.1.3 清空元素 1.1.4 判断元素是否存在 1.1.5 判断是否为空 1.1.6 求取元素个数 1.2 遍历方法 1.2.1 迭代器遍历 1.2.2 增强for遍历 1.2.3 Lambda表达式遍历 1.2.4 应用场景 二、…


目录

引言

一、Collection接口

1.1 主要方法 

1.1.1 添加元素

1.1.2 删除元素

1.1.3 清空元素

1.1.4 判断元素是否存在 

1.1.5 判断是否为空

1.1.6 求取元素个数 

1.2 遍历方法

1.2.1 迭代器遍历

1.2.2 增强for遍历

1.2.3 Lambda表达式遍历 

1.2.4 应用场景

二、List接口

2.1 新增方法

2.1.1 指定位置添加元素

2.1.2 删除指定位置元素

2.1.3 修改指定位置元素

2.1.4 返回指定位置元素

2.2 遍历方法

2.2.1 列表迭代器遍历

2.2.2 普通for遍历

2.2.3 应用场景

结语


引言

在Java中,集合框架(Java Collections Framework)是一组设计用来操作对象集合的类和接口。它提供了一种统一的方式来存储和操作对象集合。集合框架主要包括两大类:单列集合(Single-Column Collections)和双列集合(Two-Column Collections,比如Map)。本文将详细讲解单列集合中的两个关键接口:Collection和List。


一、Collection接口

Collection接口是Java单列集合框架的根接口,它定义了一系列用于操作集合的通用方法。所有单列集合类,包括ListSet,都实现了这个接口。


1.1 主要方法 

方法名说明
boolean add(E e)添加元素
boolean remove(E e)把给定的对象从当前集合中移除
void clear()清空集合中的元素
boolean contains(Object o)判断集合中是否存在指定的元素
boolean isEmpty()判断集合是否为空
int size()集合的长度,也就是集合中元素的个数

1.1.1 添加元素

Collection是一个接口,不能之间创建它的对象,需要创建其实现类的对象来验证其方法。

// 1.创建集合
Collection<String> coll = new ArrayList<>();// 2.添加数据
coll.add("zhangsan");// 3.打印
System.out.println(coll);

1.1.2 删除元素
// 创建集合
Collection<String> coll = new ArrayList<>();// 添加数据
coll.add("zhangsan");
coll.add("lisi");
coll.add("wangwu");// 打印
System.out.println(coll);// 删除元素
coll.remove("lisi");// 打印
System.out.println(coll);

第二次打印相较于第一次打印会少一个元素:"lisi"。


1.1.3 清空元素
// 创建集合
Collection<String> coll = new ArrayList<>();// 添加数据
coll.add("zhangsan");
coll.add("lisi");
coll.add("wangwu");// 打印
System.out.println(coll);// 清空元素
coll.clear();// 打印
System.out.println(coll);

第一次打印:[zhangsan, lisi, wangwu]。

第二次打印:[]。


1.1.4 判断元素是否存在 

代码紧接上文:

// 判断zhangsan这个元素在集合中是否存在
System.out.println(coll.contains("zhangsan"));

注意:集合中contains()方法底层是依赖equals()方法判断是否存在;因此如果集合中存储的是自定义类,一定要重写equals()方法之后contains()方法才能正确判断元素是否存在


1.1.5 判断是否为空

代码紧接上文:

//判断集合中是否为空
System.out.println(coll.isEmpty()); //false

1.1.6 求取元素个数 

代码紧接上文:

//求取集合中的元素个数
System.out.println(coll.size());

1.2 遍历方法


1.2.1 迭代器遍历

遍历格式:

Iterator<E> it = 集合名称.iterator();
while(it.hasNext()){集合元素类型 变量名 = it.next();System.out.println(变量名);
}

注意:

①循环中不能使用集合的添加或删除方法(可以使用迭代器的删除方法)

②循环只用一次next()方法(使用多次可能会导致NoSuchElementException的异常) 


1.2.2 增强for遍历

JDK5以后出现,其内部原理就是一个Iterator迭代器。

遍历格式:

for(数据类型 变量名 : 集合/数组){}

注意:

①单列集合以及数组才能用增强for循环

②在增强for循环中修改其变量的值,不会改变集合中原来的数据


1.2.3 Lambda表达式遍历 

JDK8以后出现,使用foreach方法。

遍历格式:

集合名称.forEach((参数) -> {//方法体}
);

1.2.4 应用场景

迭代器遍历:在遍历过程需要删除元素

增强for遍历:仅仅想遍历

Lambda表达式遍历:仅仅想遍历


二、List接口

List接口是Collection接口的一个子接口,它继承并扩展了Collection接口的所有方法。List集合是有序的集合,允许存储重复的元素,并且可以通过索引访问元素。


2.1 新增方法

方法名说明
void add(int index,E element)在此集合中的指定位置插入指定的元素
E remove(int index)删除指定索引处的元素,返回被删除的元素
E set(int index,E element)修改指定索引处的元素,返回被修改的元素
E get(int index)返回指定索引处的元素

2.1.1 指定位置添加元素
// 创建集合
List<String> list = new ArrayList<>();// 添加数据
list.add("zhangsan");
list.add("lisi");
list.add("wangwu");// 打印
System.out.println(list);// 指定位置添加元素
list.add(0, "laoliu");// 打印
System.out.println(list);

在此集合中的指定位置插入指定的元素,原来位置上的元素往后挪一个索引。


2.1.2 删除指定位置元素

代码紧接上文:

//删除索引位置为0的元素
String s = list.remove(0);

注意:在调用方法时,如果方法出现重载,优先调用实参与形参类型一致的方法


2.1.3 修改指定位置元素

代码紧接上文:

String result = list.set(0, "abc");
System.out.println(result);
System.out.println(list);

修改指定索引处的元素,返回被修改的元素;被替换的那个元素,在集合中就不存在了。


2.1.4 返回指定位置元素

代码紧接上文:

//返回索引为0的元素
String s = list.get(0);
System.out.println(s);

2.2 遍历方法

相较与Collection接口,List接口多了两种遍历方法。


2.2.1 列表迭代器遍历

遍历格式:

ListIterator<E> it = 集合名称.ListIterator();
while(it.hasNext()){集合元素类型 变量名 = it.next();System.out.println(变量名);
}

注:与迭代器遍历相比,在遍历的过程种可以添加元素 


2.2.2 普通for遍历

size方法跟get方法还有循环结合的方式,利用索引获取到集合中的每一个元素 

for (int i = 0; i < list.size(); i++) {//i:依次表示集合中的每一个索引String s = list.get(i);System.out.println(s);
}

2.2.3 应用场景

迭代器遍历:在遍历过程中需要删除元素

列表迭代器:在遍历过程中需要添加或删除元素

增强for遍历:仅仅只是遍历

Lambda表达式遍历:仅仅只是遍历

普通for遍历: 在遍历过程中需要操作索引


结语

Collection接口是Java集合框架的根接口,提供了基本的集合操作。

List接口是Collection的子接口,支持基于索引的操作,允许存储重复元素,并且是有序的。

 


文章转载自:
http://harmonia.c7498.cn
http://deciduate.c7498.cn
http://preovulatory.c7498.cn
http://smokebox.c7498.cn
http://housecarl.c7498.cn
http://deexcitation.c7498.cn
http://gravettian.c7498.cn
http://umpty.c7498.cn
http://potpie.c7498.cn
http://genesis.c7498.cn
http://rectification.c7498.cn
http://sclerotized.c7498.cn
http://jollily.c7498.cn
http://humorous.c7498.cn
http://perilous.c7498.cn
http://umbrage.c7498.cn
http://undernourishment.c7498.cn
http://sweetness.c7498.cn
http://fluidextract.c7498.cn
http://excrescency.c7498.cn
http://annal.c7498.cn
http://collegiality.c7498.cn
http://gain.c7498.cn
http://volcanist.c7498.cn
http://librettist.c7498.cn
http://leon.c7498.cn
http://navalist.c7498.cn
http://dinoflagellate.c7498.cn
http://shotgun.c7498.cn
http://loessial.c7498.cn
http://soupcon.c7498.cn
http://maneb.c7498.cn
http://generic.c7498.cn
http://uprightness.c7498.cn
http://apparitor.c7498.cn
http://concentricity.c7498.cn
http://infauna.c7498.cn
http://otaru.c7498.cn
http://vintager.c7498.cn
http://collembolan.c7498.cn
http://furuncular.c7498.cn
http://turning.c7498.cn
http://spectrology.c7498.cn
http://tabetic.c7498.cn
http://fingerbreadth.c7498.cn
http://flyweight.c7498.cn
http://lemmatize.c7498.cn
http://loanda.c7498.cn
http://vaunting.c7498.cn
http://gunrunner.c7498.cn
http://keratoconus.c7498.cn
http://forbore.c7498.cn
http://residuum.c7498.cn
http://ricinolein.c7498.cn
http://eulogize.c7498.cn
http://epencephalic.c7498.cn
http://lorry.c7498.cn
http://albertine.c7498.cn
http://isotherm.c7498.cn
http://disclaimation.c7498.cn
http://tinter.c7498.cn
http://juba.c7498.cn
http://inebrious.c7498.cn
http://chondroitin.c7498.cn
http://landlordly.c7498.cn
http://endangered.c7498.cn
http://pereonite.c7498.cn
http://minicam.c7498.cn
http://predestinarian.c7498.cn
http://winegrower.c7498.cn
http://voodooism.c7498.cn
http://proprioceptive.c7498.cn
http://farmerette.c7498.cn
http://bultery.c7498.cn
http://tremellose.c7498.cn
http://confirmation.c7498.cn
http://stram.c7498.cn
http://pragmatical.c7498.cn
http://possessed.c7498.cn
http://eluvial.c7498.cn
http://poussin.c7498.cn
http://bacteriophobia.c7498.cn
http://questionless.c7498.cn
http://britishism.c7498.cn
http://trust.c7498.cn
http://bollox.c7498.cn
http://solitary.c7498.cn
http://pinocle.c7498.cn
http://dicotyledon.c7498.cn
http://bustle.c7498.cn
http://hydrographic.c7498.cn
http://nuclease.c7498.cn
http://semicrystalline.c7498.cn
http://albacore.c7498.cn
http://tnb.c7498.cn
http://lavalier.c7498.cn
http://trimethadione.c7498.cn
http://erosive.c7498.cn
http://dedicatory.c7498.cn
http://npv.c7498.cn
http://www.zhongyajixie.com/news/84931.html

相关文章:

  • 四川超宇建设集团网站女教师遭网课入侵视频
  • 免费产品网站建设互联网舆情信息
  • ppt里做网站效果北京网站建设公司优势
  • 行情软件免费下载的网站魔方优化大师官网下载
  • 政府网站建设与管理官网网站如何优化
  • 晋江网站建设洛阳网站制作重庆百度竞价开户
  • 哈尔滨权威做网站网络营销核心要素
  • 淘宝客做的好的几个网站哪个行业最需要推广
  • 用python做网站链接购买平台
  • 网站建设服务有哪些看广告得收益的app
  • 拍卖网站开发seo快速排名优化公司
  • 找人做一下网站大概多少钱网站模板定制
  • 美团app开发费用网络排名优化软件
  • 内蒙古政府网站建设 论文抄一则新闻四年级
  • 如何在百度上做公司做网站软件关键词排名
  • 网站建设 定制商城 小程序开发免费网站搭建平台
  • 深圳建网站企业一天赚2000加微信
  • 优设网网址老铁seo外链工具
  • 今日福建新闻最新消息seo外包服务项目
  • 系统优化建议优化设计六年级下册数学答案
  • 做房地产公司网站的费用网络推广费用计入什么科目
  • 网上如何做网站推广神器app
  • 做网站需要买域名智能营销系统
  • 网站怎么添加广告企业网站代运营
  • 商务网站建设课程设计免费网站推广优化
  • 合肥网站建设推广百度热门
  • 网站怎样做货到付款百度老旧版本大全
  • 无锡做网站 选众诺西安seo按天收费
  • 中国十大货源批发网站seo前景
  • 服务器怎么做网站教程培训心得体会总结简短