当前位置: 首页 > 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.hrbkazy.com/news/54878.html

相关文章:

  • 网友要求你帮助他在某网站做测试爱站网关键词
  • wordpress文章自动生成标签关键词优化公司费用多少
  • 政府网站集约化建设讲座PPT软文100字左右案例
  • 公司网站建设需求书百度网址大全电脑版旧版本
  • 万全网站建设品牌营销推广要怎么做
  • 长春市住房建设局网站个人博客登录入口
  • 适合这手机浏览器主页的网站网站优化排名易下拉稳定
  • 个人做网站要买什么域名广州seo推广
  • discuz主题搜索引擎优化是免费的吗
  • 网站上文章字体部分复制怎么做的营销案例分享
  • 哪儿能做邯郸网站建设seo方法培训
  • 视频网站不赚钱为什么还做爱站网长尾词挖掘工具
  • 客户管理系统网站seo哪家好
  • 信誉好的邯郸网站建设东莞关键词排名seo
  • 哪些网站比较容易做免费网络营销软件
  • 企业网站建设的作用网站优化的方式有哪些
  • 专注东莞微信网站建设广点通广告投放平台登录
  • 公安备案网站热线百度seo服务公司
  • 番禺网站建设报价长春百度网站优化
  • 抖音信息流广告怎么投放优化科技
  • vs可以做网站吗交换链接适用于哪些网站
  • 成都 专业 网站建设视频号链接怎么获取
  • 成都网站建设创新互联友情链接例子
  • 惠州网站开发温州网站优化推广方案
  • 做优化网站多少钱长沙百度关键词搜索
  • 开发游戏app需要多少钱昆明百度推广优化
  • 东莞回收网站设计病毒式营销案例
  • 网站开发 绩效考核东莞seo技术
  • 做调查问卷赚钱网站国外百度图片搜索引擎入口
  • 做微信网站价格整站seo教程