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

qq空间可以做网站吗服务之家网站推广

qq空间可以做网站吗,服务之家网站推广,项目管理软件开源,提高索引量的方法写在开头:本文用于作者学习Java常用API 我将官方文档中Collections类中所有API全测了一遍并打印了结果,日拱一卒,常看常新 addAll() 将所有指定元素添加到指定 collection 中 可以添加一个或多个元素 Testpublic void test_addAl…

写在开头:本文用于作者学习Java常用API

我将官方文档中Collections类中所有API全测了一遍并打印了结果,日拱一卒,常看常新

addAll()

将所有指定元素添加到指定 collection 中
        可以添加一个或多个元素

@Testpublic void test_addAll(){/*将所有指定元素添加到指定 collection 中* 可以添加一个或多个元素*/ArrayList<String> strings = new ArrayList<>();strings.add("1");strings.add("2");strings.add("3");Collections.addAll(strings, "a","b","c");System.out.println(strings);//[1, 2, 3, a, b, c]System.out.println(Collections.addAll(strings, "d"));System.out.println(strings);//[1, 2, 3, a, b, c, d]}

asLifQueue()

该方法用于将指定的Deque(双端队列)转换为后进先出(LIFO)队列

@Testpublic void test_asLifQueue(){/*该方法用于将指定的Deque(双端队列)转换为后进先出(LIFO)队列。*/ArrayDeque<String> deque = new ArrayDeque<>();deque.add("first");deque.add("second");deque.add("third");System.out.println(deque);//[first, second, third]Queue<String> queue = Collections.asLifoQueue(deque);while (!queue.isEmpty()){String poll = queue.poll();System.out.println(poll);//转换为后进先出(LIFO)队列时,并不改变元素的顺序,而是将Deque视为LIFO队列。因此,在使用poll方法时,仍然是按照Deque的顺序取出元素,而不是按照后进先出的顺序。/*firstsecondthird*/}}

binarySearch()

输入指定元素,返回对应的下标

        -5:该元素不存在

@Testpublic void test_binarySearch(){/*输入指定元素,返回对应的下标-5:该元素不存在*/List<Integer> list = Arrays.asList(1, 2, 3, 4);System.out.println(Collections.binarySearch(list, 1));//0System.out.println(Collections.binarySearch(list, 2));//1System.out.println(Collections.binarySearch(list, 5));//-5 表示不存在System.out.println(Collections.binarySearch(list, 8));//-5System.out.println(Collections.binarySearch(list, 11));//-5}

copy()

将所有元素从一个列表复制到另一个列表。第一个参数是目标列表,第二个是源列表

        目标列表长度必须不小于源列表

@Testpublic void test_copy(){/*将所有元素从一个列表复制到另一个列表。第一个参数是目标列表,第二个是源列表* 目标列表长度必须不小于源列表*/List<Integer> src = Arrays.asList(1, 2, 3, 4);List<Integer> dest = Arrays.asList(0,0,0,0);Collections.copy(dest,src);System.out.println(dest);//[1, 2, 3, 4]List<Object> dest1 = Collections.emptyList();//造一个空列表/*Collections.copy(dest1,src);//报错:目标列表长度小于源列表长度System.out.println(dest1);//IndexOutOfBoundsException: Source does not fit in dest*/List<Object> dest2 = Collections.nCopies(4, null);//会生成一个包含4个null元素的不可变列表System.out.println(dest2);//[null, null, null, null]/*Collections.copy(dest2,src);//报错:UnsupportedOperationExceptionSystem.out.println(dest2);*/ArrayList<Integer> dest3 = new ArrayList<>();dest3.add(0);dest3.add(0);dest3.add(0);dest3.add(0);dest3.add(0);Collections.copy(dest3,src);System.out.println(dest3);//[1, 2, 3, 4, 0]}

disjoint()

判断两个集合是否完全不包含对方集合的元素
        完全不包含,返回 true。
        哪怕包含1个,都返回false

@Testpublic void test_disjoint(){/*判断两个集合是否完全不包含对方集合的元素完全不包含,返回 true。哪怕包含1个,都返回false*/List<Integer> c1 = Arrays.asList(1, 2, 3, 4);List<Integer> c2 = Arrays.asList(1, 2, 3, 4);System.out.println(Collections.disjoint(c1, c2));//falseList<Integer> c3 = Arrays.asList(1, 5, 6);System.out.println(Collections.disjoint(c1, c3));//falseList<Integer> c4 = Arrays.asList(7, 5, 6);System.out.println(Collections.disjoint(c1, c4));//true}

emptyList()

返回一个不可变空列表

@Testpublic void test_emptyList(){/*返回一个不可变空列表* 意义:* 1. 节省内存:由于空列表是不可变的,可以在不需要实际数据的情况下节省内存空间。在某些场景下,需要一个空列表作为占位符或默认返回值,此时使用Collections.emptyList()可以避免创建多个空列表对象。2. 避免空指针异常:在某些情况下,需要返回一个空列表而不是null,以避免空指针异常。使用Collections.emptyList()可以提供一个安全的空列表对象。3. API一致性:在一些API设计中,需要返回一个空列表作为特定情况的标识符,使用Collections.emptyList()可以保持API的一致性和规范性。虽然Collections.emptyList()返回的空列表不能被修改,但它在某些情况下仍然具有一定的实用性和意义。*/List<Object> objects = Collections.emptyList();System.out.println(objects);//[]//        System.out.println(objects.add("dahua"));//UnsupportedOperationException}

emptyMap()

返回1个空的map(不可变的)

@Testpublic void test_emptyMap(){/*返回1个空的map(不可变的)。*/Map<Object, Object> objectMap = Collections.emptyMap();System.out.println(objectMap);//{}}

emptySet()

返回1个空的set(不可变的)

@Testpublic void test_emptySet(){/*返回1个空的set(不可变的)*/Set<Object> objectSet = Collections.emptySet();System.out.println(objectSet);//[]}

enumeration()

返回一个枚举类型的列表

@Testpublic void test_enumeration(){/*返回一个枚举类型的列表*/List<String> c = Arrays.asList("dahua", "xiaoyabing", "sangxinran", "fangmangmang");Enumeration<String> enumeration = Collections.enumeration(c);System.out.println(enumeration);//java.util.Collections$3@3d82c5f3while (enumeration.hasMoreElements()){System.out.println(enumeration.nextElement());}/*dahuaxiaoyabingsangxinranfangmangmang*/}

fill()

使用指定元素替换、填充指定列表中的所有元素

@Testpublic void test_fill(){/*使用指定元素替换、填充指定列表中的所有元素*/List<String> c = Arrays.asList("dahua", "xiaoxiao", "xiaosang", "xiaofang");Collections.fill(c,"lgf");System.out.println(c);//[lgf, lgf, lgf, lgf]}

frequency()

返回集合中指定对象的个数

@Testpublic void test_frequency(){/*返回集合中指定对象的个数*/List<String> c = Arrays.asList("dahua", "xiaoxiao", "xiaosang", "xiaofang","xiaofang");System.out.println(Collections.frequency(c, "xiaofang"));//2System.out.println(Collections.frequency(c, "dahua"));//1}

indexOfSubList()

返回一个数组列表,它按返回顺序包含指定枚举返回的元素

@Testpublic void test_indexOfSubList(){/*返回指定源列表中第一次出现指定目标列表的起始位置;如果没有出现这样的列表,则返回 -1*/List<String> src = Arrays.asList("dahua", "xiaoxiao", "xiaosang", "xiaofang","xiaofang");List<String> target = Arrays.asList("dahua", "xiaoxiao", "xiaosang", "xiaofang","xiaofang");System.out.println(Collections.indexOfSubList(src, target));//0List<String> target1= Arrays.asList("dahua", "xiaoxiao", "xiaosang", "xiaofang","xiaofang","dahai");System.out.println(Collections.indexOfSubList(src, target1));//-1}

list()

返回一个数组列表,它按返回顺序包含指定枚举返回的元素

@Testpublic void test_list(){/*返回一个数组列表,它按返回顺序包含指定枚举返回的元素*/List<String> c = Arrays.asList("dahua", "xiaoyabing", "sangxinran", "fangmangmang");Enumeration<String> enumeration = Collections.enumeration(c);ArrayList<String> list = Collections.list(enumeration);System.out.println(list);//[dahua, xiaoyabing, sangxinran, fangmangmang]Vector<String> vector  = new Vector<>();vector.add("Apple");vector.add("Banana");vector.add("Orange");Enumeration<String> elements = vector.elements();ArrayList<String> list1 = Collections.list(elements);System.out.println(list1);//[Apple, Banana, Orange]}

max()

根据元素的自然顺序,返回集合中的最大元素
        *
        * 也可以自定义排序规则

@Testpublic void test_max(){/*根据元素的自然顺序,返回集合中的最大元素** 也可以自定义排序规则*/List<String> coll = Arrays.asList("dahua", "xiaoyabing", "sangxinran", "fangmangmang");System.out.println(Collections.max(coll));//xiaoyabing/*自定义大小规则第二个参数写比较器,返回给定 集合 的最大元素*/String max = Collections.max(coll, new Comparator<String>() {@Overridepublic int compare(String o1, String o2) {int i = o1.substring(0).hashCode();int i1 = o2.substring(0).hashCode();return i - i1;}});System.out.println(max);//fangmangmang}

min()

返回集合最小元素

@Testpublic void test_min(){/** 返回集合最小元素* */
//        Collections.min()}

nCopies()

返回由指定对象的 n 个副本组成的不可变列表

@Testpublic void test_nCopies(){/*返回由指定对象的 n 个副本组成的不可变列表*/List<String> dahua = Collections.nCopies(5, "dahua");System.out.println(dahua);//[dahua, dahua, dahua, dahua, dahua]List<Object> objects = Collections.nCopies(5, null);System.out.println(objects);//[null, null, null, null, null]/*objects.add("xiaomei");//UnsupportedOperationException,不可变了System.out.println(objects);*/}

newSetFromMap()

将Map转成set结构,前提是map必须为空

@Testpublic void test_newSetFromMap(){/*将Map转成set结构,前提是map必须为空*/Map<String, Boolean> map = new HashMap<>();map.put("Apple", true);map.put("Banana", false);map.put("Orange", true);
//        Set<String> set1 = Collections.newSetFromMap(map);//IllegalArgumentException: Map is non-empty:map必须为空map.clear();Set<String> set = Collections.newSetFromMap(map);}

replaceAll()

用一个值替换集合原有子串

@Testpublic void test_replaceAll(){/*我的:用一个值替换集合原有子串官方:使用另一个值替换列表中出现的所有某一指定值*/List<String> list = Arrays.asList("dahua", "xiaoyabing", "sangxinran", "fangmangmang");Collections.replaceAll(list,"dahua","xiaoliang");System.out.println(list);//[xiaoliang, xiaoyabing, sangxinran, fangmangmang]}

reverse()

列表元素反转

@Testpublic void test_reverse(){/*列表元素反转*/List<String> list = Arrays.asList("dahua", "xiaoyabing", "sangxinran", "fangmangmang");Collections.reverse(list);System.out.println(list);//[fangmangmang, sangxinran, xiaoyabing, dahua]}

rotate()

指定的距离循环滚动

@Testpublic void test_rotate(){/*指定的距离循环滚动*/List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);// 将列表向右循环移动2个位置,第一个元素往右走两格Collections.rotate(list, 2);System.out.println(list);//[4, 5, 1, 2, 3]}

shuffle()

将列表元素随机打乱

@Testpublic void test_shuffle(){/*将列表元素随机打乱*/List<Integer> list = Arrays.asList(1, 2, 3, 4, 5);Collections.shuffle(list);System.out.println(list);//[3, 5, 4, 1, 2] 第一次运行结果System.out.println(list);//[2, 5, 4, 3, 1] 第二次运行结果System.out.println(list);//[4, 3, 2, 5, 1] 第三次运行结果}

singleton()

返回一个只包含指定对象的不可变 set

Testpublic void test_singleton(){/*返回一个只包含指定对象的不可变 set*/List<String> list = Arrays.asList("dahua", "dahua", "sangxinran", "fangmangmang");Set<List<String>> singleton = Collections.singleton(list);System.out.println(singleton);//[[dahua, dahua, sangxinran, fangmangmang]]}

http://www.yidumall.com/news/19666.html

相关文章:

  • 付钱做编程题目的网站百度网盘登录入口官网
  • 网站管理工具电池优化大师下载
  • 房产网站建设网站排名seo培训
  • 珠宝公司网站模板网络广告有哪些
  • 上海专业做网站建设公司怎么查权重查询
  • iis7.5 部署网站链接购买
  • 四川酒店网站建设重庆可靠的关键词优化研发
  • 图片加文字制作seo快速排名软件网站
  • 菏泽 网站建设如何做好企业网站的推广
  • 网址导航网站有哪些百度高级搜索
  • 广州微网站开发化工seo顾问
  • 婚庆公司网站怎么做软文推广名词解释
  • 天猫商城网站风格汽车行业网站建设
  • 人民政府网seo博客推广
  • 网站可以做腾讯广告联盟网站关键词优化案例
  • 有做销售产品的网站有哪些重庆森林粤语
  • 什么网站可以找人做系统怎么搜索网站
  • 网站建设成立领导小组怎么制作自己公司网站
  • 台州高端网站建设百度公司总部
  • 料神wordpress建站教程安卓神级系统优化工具
  • wordpress配置数据库主机名正规seo关键词排名网络公司
  • 郑州网站建设公司哪家专业关键词制作软件
  • 网站怎么做才被收录快竞价排名采用什么计费方式
  • 南宁网站设嘉兴百度快照优化排名
  • 网站备案视频网络优化培训要多少钱
  • 网络网站技能培训机构
  • 网站网页制作图片素材服务营销案例100例
  • 建设网站职业证书友链之家
  • 网站建设使用的工具抖音关键词搜索排名
  • 对我国政府网站建设和管理的现状苏州百度推广服务中心