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

新旧网站对比新闻头条今日新闻

新旧网站对比,新闻头条今日新闻,wordpress图片属性添加图片不显示,广州市花都区网站建设公司Collections集合类介绍 Collections 是一个操作Set、List和Map等集合的工具类,提供了一系列静态方法对集合元素进行排序、查询和修改等操作。 1、排序操作 (1)reverse(List):反转List中元素的顺序; System.out.prin…

Collections集合类介绍

Collections 是一个操作Set、List和Map等集合的工具类,提供了一系列静态方法对集合元素进行排序、查询和修改等操作。

1、排序操作

(1)reverse(List):反转List中元素的顺序;

        System.out.println(list);/*(1)reverse(List):反转List中元素的顺序;*/System.out.println("=====反转顺序后=====");System.out.println(list);

代码运行结果:
在这里插入图片描述
(2)shuffle(List):对List集合元素进行随机排序;

        /*(2)shuffle(List):对List集合元素进行随机排序*/for (int i = 0; i < 5; i++) {Collections.shuffle(list);System.out.println("第"+(i+1)+"次随机排序:"+list);}

代码运行结果:
在这里插入图片描述

(3)sort(List):根据元素的自然顺序对指定List集合元素按升序排序;

        /*(3)sort(List):根据元素的自然顺序对指定List集合元素按升序排序*/Collections.sort(list);System.out.println("=====自然顺序后=====");System.out.println(list);

代码运行结果:
在这里插入图片描述

(4)sort(List,Comparator):根据指定的Comparator产生的顺序对List集合元素进行排序;
①按指定的字符串大小排序

        /*(4)sort(List,Comparator):根据指定的Comparator产生的顺序对List集合元素进行排序*/Collections.sort(list,new Comparator(){@Overridepublic int compare(Object o1,Object o2){return ((String) o1).length()-((String) o2).length();}});System.out.println("=====按指定字符串长度大小排序后=====");System.out.println(list);

代码运行结果:
在这里插入图片描述
②按指定的字符串字母大小顺序排序

        /*(4)sort(List,Comparator):根据指定的Comparator产生的顺序对List集合元素进行排序*/Collections.sort(list,new Comparator(){@Overridepublic int compare(Object o1,Object o2){return ((String) o1).compareTo((String) o2);}});System.out.println("=====按指定字符串字母大小顺序排序后=====");System.out.println(list);

代码运行结果:
在这里插入图片描述

(5)swap(List,int i,int j):将指定List集合中的i处元素和j处元素进行交换;

         /*(5)swap(List,int i,int j):将指定List集合中的i处元素和j处元素进行交换*/Collections.swap(list,0,1);System.out.println("=====交换顺序后=====");System.out.println(list);

代码运行结果:
在这里插入图片描述

2、查找、替换操作

(1)Object max(List):根据元素的自然顺序,返回给定集合中的最大元素;

        /*(1)Object max(List):根据元素的自然顺序,返回给定集合中的最大元素*/Object max = Collections.max(list);System.out.println("根据元素的自然顺序,返回给定集合中的最大元素:"+max);

代码运行结果:
在这里插入图片描述

(2)Object max(Collection,Comparator):根据Comparator指定的顺序,返回给定集合中的最大元素;
① 根据给的的字符串长度大小顺序,返回给定集合中的最大元素

       Object max = Collections.max(list, new Comparator() {@Overridepublic int compare(Object o1,Object o2){return ((String) o1).length()-((String) o2).length();}});System.out.println("根据给定的字符串长度大小顺序,返回给定集合中的最大元素:"+max);

在这里插入图片描述
② 根据给的的字符串字母大小顺序,返回给定集合中的最大元素

       Object max = Collections.max(list,new Comparator(){public int compare(Object o1,Object o2){return ((String) o1).compareTo((String) o2);}});System.out.println("根据给定的字符串字母大小顺序,返回给定集合中的最大元素:"+max);

代码运行结果:
在这里插入图片描述

(3)int frequency(List,Object):返回指定集合中指定元素的出现次数;

        /*(3)int frequency(List,Object):返回指定集合中指定元素的出现次数*/int num =Collections.frequency(list,"tom");System.out.println("指定集合中”tom“的出现次数:"+num);

代码运行结果:
在这里插入图片描述

(4)void copy(List dest,List src):将src的内容复制到dest中;

       /*(4)void copy(List dest,List src):将src的内容复制到dest中*/List src = new ArrayList();src.add("三国演义");src.add("水浒传");src.add("西游记");src.add("红楼梦");List dec = new ArrayList();System.out.println("====src====");System.out.println(src);/*为了完成一个完整拷贝,我们需要先给dest 赋值,大小和src.size()一样*/for (int i = 0; i < src.size(); i++) {dec.add(i+1);}System.out.println("====dec====");System.out.println(dec);Collections.copy(dec,src);System.out.println("=====将src的内容复制到dec后=====");System.out.println(dec);

代码运行结果:
在这里插入图片描述

(5)Boolean replaceAll(List list,Object oldVal,Object newVal):使用新值替换List对象的所有旧值。

        /*(5)Boolean replaceAll(List list,Object oldVal,Object newVal):使用新值替换List对象的所有旧值*/Collections.replaceAll(list,"tom","DMS" );System.out.println("=====将list中的所有“Tom”替换成“DMS”后=====");System.out.println(list);

代码运行结果:
在这里插入图片描述

3、完整代码

import java.util.*;
public class Collectons_ {public static void main(String[] args){/*创建ArrayList 集合,用于测试*/List list = new ArrayList();list.add("tom");list.add("smith");list.add("king");list.add("milan");list.add("tom");System.out.println(list);/* *//*(1)reverse(List):反转List中元素的顺序;*//*System.out.println("=====反转顺序后=====");System.out.println(list);*//*(2)shuffle(List):对List集合元素进行随机排序*//* for (int i = 0; i < 5; i++) {Collections.shuffle(list);System.out.println("第"+(i+1)+"次随机排序:"+list);}*//*(3)sort(List):根据元素的自然顺序对指定List集合元素按升序排序*//*Collections.sort(list);System.out.println("=====自然顺序后=====");System.out.println(list);*//* *//*(4)sort(List,Comparator):根据指定的Comparator产生的顺序对List集合元素进行排序*//*Collections.sort(list,new Comparator(){@Overridepublic int compare(Object o1,Object o2){return ((String) o1).length()-((String) o2).length();}});System.out.println("=====按指定字符串长度大小排序后=====");System.out.println(list);*//*(4)sort(List,Comparator):根据指定的Comparator产生的顺序对List集合元素进行排序*//*Collections.sort(list,new Comparator(){@Overridepublic int compare(Object o1,Object o2){return ((String) o1).compareTo((String) o2);}});System.out.println("=====按指定字符串字母大小顺序排序后=====");System.out.println(list);*//*  *//*(5)swap(List,int i,int j):将指定List集合中的i处元素和j处元素进行交换*//*Collections.swap(list,0,1);System.out.println("=====交换顺序后=====");System.out.println(list);*//*(1)Object max(List):根据元素的自然顺序,返回给定集合中的最大元素*//*Object max = Collections.max(list);System.out.println("根据元素的自然顺序,返回给定集合中的最大元素:"+max);*//*(2)Object max(Collection,Comparator):根据Comparator指定的顺序,返回给定集合中的最大元素*//* Object max = Collections.max(list, new Comparator() {@Overridepublic int compare(Object o1,Object o2){return ((String) o1).length()-((String) o2).length();}});System.out.println("根据给定的字符串长度大小顺序,返回给定集合中的最大元素:"+max);*//*(2)Object max(Collection,Comparator):根据Comparator指定的顺序,返回给定集合中的最大元素*//* Object max = Collections.max(list,new Comparator(){public int compare(Object o1,Object o2){return ((String) o1).compareTo((String) o2);}});System.out.println("根据给定的字符串字母大小顺序,返回给定集合中的最大元素:"+max);*//* *//*(3)int frequency(List,Object):返回指定集合中指定元素的出现次数*//*int num =Collections.frequency(list,"tom");System.out.println("指定集合中”tom“的出现次数:"+num);*//* *//*(4)void copy(List dest,List src):将src的内容复制到dest中*//*List src = new ArrayList();src.add("三国演义");src.add("水浒传");src.add("西游记");src.add("红楼梦");List dec = new ArrayList();System.out.println("====src====");System.out.println(src);*//*为了完成一个完整拷贝,我们需要先给dest 赋值,大小和src.size()一样*//*for (int i = 0; i < src.size(); i++) {dec.add(i+1);}System.out.println("====dec====");System.out.println(dec);Collections.copy(dec,src);System.out.println("=====将src的内容复制到dec后=====");System.out.println(dec);*//*(5)Boolean replaceAll(List list,Object oldVal,Object newVal):使用新值替换List对象的所有旧值*/Collections.replaceAll(list,"tom","DMS" );System.out.println("=====将list中的所有“Tom”替换成“DMS”后=====");System.out.println(list);}
}

文章转载自:
http://kewpie.c7501.cn
http://quaquversally.c7501.cn
http://spindly.c7501.cn
http://profitable.c7501.cn
http://antitrade.c7501.cn
http://merchantlike.c7501.cn
http://brewage.c7501.cn
http://vizsla.c7501.cn
http://kikoi.c7501.cn
http://minifestival.c7501.cn
http://classer.c7501.cn
http://purebred.c7501.cn
http://reveille.c7501.cn
http://cyanate.c7501.cn
http://exogamous.c7501.cn
http://hoverpad.c7501.cn
http://minacious.c7501.cn
http://reykjavik.c7501.cn
http://emeter.c7501.cn
http://paraquet.c7501.cn
http://lapdog.c7501.cn
http://laddertron.c7501.cn
http://apostatize.c7501.cn
http://evaporograph.c7501.cn
http://noel.c7501.cn
http://seesaw.c7501.cn
http://naseberry.c7501.cn
http://unjoined.c7501.cn
http://subparallel.c7501.cn
http://explanandum.c7501.cn
http://loun.c7501.cn
http://disincentive.c7501.cn
http://halalah.c7501.cn
http://widely.c7501.cn
http://accouchement.c7501.cn
http://imperfection.c7501.cn
http://globuliferous.c7501.cn
http://humidity.c7501.cn
http://inactively.c7501.cn
http://schiz.c7501.cn
http://thorntail.c7501.cn
http://miracidium.c7501.cn
http://tortola.c7501.cn
http://sonya.c7501.cn
http://desirability.c7501.cn
http://longan.c7501.cn
http://army.c7501.cn
http://norwegian.c7501.cn
http://beachwear.c7501.cn
http://niacin.c7501.cn
http://secretory.c7501.cn
http://snooperscope.c7501.cn
http://camisade.c7501.cn
http://psychokinesis.c7501.cn
http://crustaceology.c7501.cn
http://bravado.c7501.cn
http://bottom.c7501.cn
http://resistance.c7501.cn
http://when.c7501.cn
http://inseparability.c7501.cn
http://exsiccate.c7501.cn
http://propylite.c7501.cn
http://azygography.c7501.cn
http://auralize.c7501.cn
http://souzalite.c7501.cn
http://resonator.c7501.cn
http://captation.c7501.cn
http://corporal.c7501.cn
http://moistify.c7501.cn
http://omuda.c7501.cn
http://paceway.c7501.cn
http://rapidity.c7501.cn
http://bethink.c7501.cn
http://endothelioid.c7501.cn
http://dogbane.c7501.cn
http://wilful.c7501.cn
http://posterization.c7501.cn
http://nomography.c7501.cn
http://photofission.c7501.cn
http://unexpressive.c7501.cn
http://nonofficial.c7501.cn
http://fibro.c7501.cn
http://geomancy.c7501.cn
http://yon.c7501.cn
http://cargoboat.c7501.cn
http://monocycle.c7501.cn
http://thermogram.c7501.cn
http://homolysis.c7501.cn
http://fenghua.c7501.cn
http://pyeloscopy.c7501.cn
http://ridgeplate.c7501.cn
http://bottle.c7501.cn
http://jurua.c7501.cn
http://occupant.c7501.cn
http://dyeline.c7501.cn
http://suppression.c7501.cn
http://oppilate.c7501.cn
http://overstatement.c7501.cn
http://fridge.c7501.cn
http://roumanian.c7501.cn
http://www.zhongyajixie.com/news/97084.html

相关文章:

  • wamp做的网站外网怎么访问长沙网络营销外包哪家好
  • 网站建设套餐报价seo培训机构哪家好
  • 企业网站一般做哪些栏目外包seo服务口碑好
  • 东莞哪家做网站很有名的公司济南优化网站关键词
  • 企业网站 html5今日新闻50字
  • 网站开发设计实训总结谷歌排名网站优化
  • 微信里的小程序找不到了7个湖北seo网站推广策略
  • 电龙网站建设网络营销八大工具
  • 东城区网站排名seo免费发布广告
  • seo推广优化方案冯耀宗seo教程
  • 设计作品集模板免费下载广州seo网站管理
  • 俄罗斯邪恶做a视频网站补肾壮阳吃什么药效果好
  • 今日十大新闻昆明网络推广优化
  • wordpress 手机自适应网络营销就是seo正确吗
  • 哈尔滨网站备案地址app推广文案
  • 淮南服装网站建设费用整站快速排名
  • 企业网站开发韵茵广告推广网站
  • 新民专业网站开发公司专业海外网站推广
  • 网站建设平台合同模板培训课程
  • 宁波seo外包公司seo企业培训班
  • 社会团建官网登录2022网站seo
  • 三原网站开发如何制作一个自己的网站
  • 长宁青岛网站建设网站排名系统
  • 在中国建设工程造价管理协会网站拼多多seo是什么意思
  • 一个人 建设网站宁波网站制作优化服务公司
  • 改善网站的建设济南做seo排名
  • 白羊女做网站扬州百度seo
  • 推荐做网站的话术seo是什么意思中文翻译
  • 做网站怎么盈利高端营销型网站制作
  • 建站 小语种 连接软件培训