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

西安单位网站制作达人室内设计网论坛

西安单位网站制作,达人室内设计网论坛,网站开发简易软件,哪里可以做网站系统写在开头#xff1a;本文用于作者学习Java常用API 我将官方文档中Collections类中所有API全测了一遍并打印了结果#xff0c;日拱一卒#xff0c;常看常新 addAll() 将所有指定元素添加到指定 collection 中 可以添加一个或多个元素 Testpublic void test_addAl…写在开头本文用于作者学习Java常用API 我将官方文档中Collections类中所有API全测了一遍并打印了结果日拱一卒常看常新 addAll() 将所有指定元素添加到指定 collection 中         可以添加一个或多个元素 Testpublic void test_addAll(){/*将所有指定元素添加到指定 collection 中* 可以添加一个或多个元素*/ArrayListString 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队列。*/ArrayDequeString deque new ArrayDeque();deque.add(first);deque.add(second);deque.add(third);System.out.println(deque);//[first, second, third]QueueString 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该元素不存在*/ListInteger 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(){/*将所有元素从一个列表复制到另一个列表。第一个参数是目标列表第二个是源列表* 目标列表长度必须不小于源列表*/ListInteger src Arrays.asList(1, 2, 3, 4);ListInteger dest Arrays.asList(0,0,0,0);Collections.copy(dest,src);System.out.println(dest);//[1, 2, 3, 4]ListObject dest1 Collections.emptyList();//造一个空列表/*Collections.copy(dest1,src);//报错目标列表长度小于源列表长度System.out.println(dest1);//IndexOutOfBoundsException: Source does not fit in dest*/ListObject dest2 Collections.nCopies(4, null);//会生成一个包含4个null元素的不可变列表System.out.println(dest2);//[null, null, null, null]/*Collections.copy(dest2,src);//报错UnsupportedOperationExceptionSystem.out.println(dest2);*/ArrayListInteger 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*/ListInteger c1 Arrays.asList(1, 2, 3, 4);ListInteger c2 Arrays.asList(1, 2, 3, 4);System.out.println(Collections.disjoint(c1, c2));//falseListInteger c3 Arrays.asList(1, 5, 6);System.out.println(Collections.disjoint(c1, c3));//falseListInteger 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()返回的空列表不能被修改但它在某些情况下仍然具有一定的实用性和意义。*/ListObject objects Collections.emptyList();System.out.println(objects);//[]// System.out.println(objects.add(dahua));//UnsupportedOperationException} emptyMap() 返回1个空的map不可变的 Testpublic void test_emptyMap(){/*返回1个空的map不可变的。*/MapObject, Object objectMap Collections.emptyMap();System.out.println(objectMap);//{}} emptySet() 返回1个空的set不可变的 Testpublic void test_emptySet(){/*返回1个空的set不可变的*/SetObject objectSet Collections.emptySet();System.out.println(objectSet);//[]} enumeration() 返回一个枚举类型的列表 Testpublic void test_enumeration(){/*返回一个枚举类型的列表*/ListString c Arrays.asList(dahua, xiaoyabing, sangxinran, fangmangmang);EnumerationString enumeration Collections.enumeration(c);System.out.println(enumeration);//java.util.Collections$33d82c5f3while (enumeration.hasMoreElements()){System.out.println(enumeration.nextElement());}/*dahuaxiaoyabingsangxinranfangmangmang*/} fill() 使用指定元素替换、填充指定列表中的所有元素 Testpublic void test_fill(){/*使用指定元素替换、填充指定列表中的所有元素*/ListString c Arrays.asList(dahua, xiaoxiao, xiaosang, xiaofang);Collections.fill(c,lgf);System.out.println(c);//[lgf, lgf, lgf, lgf]} frequency() 返回集合中指定对象的个数 Testpublic void test_frequency(){/*返回集合中指定对象的个数*/ListString 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*/ListString src Arrays.asList(dahua, xiaoxiao, xiaosang, xiaofang,xiaofang);ListString target Arrays.asList(dahua, xiaoxiao, xiaosang, xiaofang,xiaofang);System.out.println(Collections.indexOfSubList(src, target));//0ListString target1 Arrays.asList(dahua, xiaoxiao, xiaosang, xiaofang,xiaofang,dahai);System.out.println(Collections.indexOfSubList(src, target1));//-1} list() 返回一个数组列表它按返回顺序包含指定枚举返回的元素 Testpublic void test_list(){/*返回一个数组列表它按返回顺序包含指定枚举返回的元素*/ListString c Arrays.asList(dahua, xiaoyabing, sangxinran, fangmangmang);EnumerationString enumeration Collections.enumeration(c);ArrayListString list Collections.list(enumeration);System.out.println(list);//[dahua, xiaoyabing, sangxinran, fangmangmang]VectorString vector new Vector();vector.add(Apple);vector.add(Banana);vector.add(Orange);EnumerationString elements vector.elements();ArrayListString list1 Collections.list(elements);System.out.println(list1);//[Apple, Banana, Orange]} max() 根据元素的自然顺序返回集合中的最大元素         *         * 也可以自定义排序规则 Testpublic void test_max(){/*根据元素的自然顺序返回集合中的最大元素** 也可以自定义排序规则*/ListString coll Arrays.asList(dahua, xiaoyabing, sangxinran, fangmangmang);System.out.println(Collections.max(coll));//xiaoyabing/*自定义大小规则第二个参数写比较器返回给定 集合 的最大元素*/String max Collections.max(coll, new ComparatorString() {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 个副本组成的不可变列表*/ListString dahua Collections.nCopies(5, dahua);System.out.println(dahua);//[dahua, dahua, dahua, dahua, dahua]ListObject 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必须为空*/MapString, Boolean map new HashMap();map.put(Apple, true);map.put(Banana, false);map.put(Orange, true); // SetString set1 Collections.newSetFromMap(map);//IllegalArgumentException: Map is non-empty:map必须为空map.clear();SetString set Collections.newSetFromMap(map);} replaceAll() 用一个值替换集合原有子串 Testpublic void test_replaceAll(){/*我的用一个值替换集合原有子串官方使用另一个值替换列表中出现的所有某一指定值*/ListString 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(){/*列表元素反转*/ListString list Arrays.asList(dahua, xiaoyabing, sangxinran, fangmangmang);Collections.reverse(list);System.out.println(list);//[fangmangmang, sangxinran, xiaoyabing, dahua]} rotate() 指定的距离循环滚动 Testpublic void test_rotate(){/*指定的距离循环滚动*/ListInteger 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(){/*将列表元素随机打乱*/ListInteger 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*/ListString list Arrays.asList(dahua, dahua, sangxinran, fangmangmang);SetListString singleton Collections.singleton(list);System.out.println(singleton);//[[dahua, dahua, sangxinran, fangmangmang]]}
http://www.dnsts.com.cn/news/178145.html

相关文章:

  • 个人相册网站建设报告沈阳网站建设技术公司
  • 网站做标准曲线优秀门户网站欣赏
  • 芜湖做网站多少钱静态网站怎么做百度推广
  • 网站开发 认证seo教程排名第一
  • 网站推广临沂wordpress woff
  • 蓝色风格网站模板wordpress数据恢复
  • 大良网站建设市场做网站有用吗
  • 南京 网站开发什么待遇啊网速
  • 网站建设账务处理中国建设银采购发文网站
  • 网站改版数据来源表改怎么做网站建设可用性的五个标准
  • 怎样制作图片网站国内用react做的网站
  • 做网站现在可以挣钱吗wordpress百度云下载文件
  • 广州网站开发公司石碣仿做网站
  • 自己电脑做网站需要什么设备哈尔滨市建设厅网站
  • 网站关键词如何快速上首页廊坊网络推广公司
  • html代码特效搜索引擎简称seo
  • 网站建设干货市场调研是什么工作
  • 网站建设一对一培训班企业制作宣传片拍摄
  • 只用html5做网站杭州正规引流推广公司
  • 为网站营销好处债权债务交易网站开发
  • 新增网站 备案阿里云服务器多个网站
  • 网站是谁做的自己做的网站谁来维护
  • 做投票页面什么网站好四川网站建设培训班
  • 深圳企业学校网站建设医院网站制作公司
  • 做网站除了dwdelphi+WordPress
  • 电子商务网站建设基础项目实训免费装修设计图
  • 做网站公司怎么样中国核工业第五建设有限公司简介
  • 凡科建站好用吗代做寄生虫网站
  • 自己做的网站有排名吗专业的led网站建设
  • 大连网站建设制作建设网站用什么软件下载