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

上门做网站哪家好自己做网站流程

上门做网站哪家好,自己做网站流程,做网站建设的销售薪水,网站构建是什么1、使用 LinkedHashSet 删除 arraylist 中的重复数据 LinkedHashSet 是在一个 ArrayList 删除重复数据的最佳方法。LinkedHashSet 在内部完成两件事: 删除重复数据 保持添加到其中的数据的顺序 Java 示例使用 LinkedHashSet 删除 arraylist 中的重复项。在给定的示例…

1、使用 LinkedHashSet 删除 arraylist 中的重复数据

LinkedHashSet 是在一个 ArrayList 删除重复数据的最佳方法。LinkedHashSet 在内部完成两件事:

删除重复数据

保持添加到其中的数据的顺序

Java 示例使用 LinkedHashSet 删除 arraylist 中的重复项。在给定的示例中,numbersList 是包含整数的
arraylist,其中一些是重复的数字。

例如 1,3 和 5. 我们将列表添加到 LinkedHashSet,然后将内容返回到列表中。结果 arraylist 没有重复的整数。


import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedHashSet;public class ArrayListExample
{public static void main(String[] args){ArrayList<Integer> numbersList = new ArrayList<>(Arrays.asList(1, 1, 2, 3, 3, 3, 4, 5, 6, 6, 6, 7, 8));System.out.println(numbersList);LinkedHashSet<Integer> hashSet = new LinkedHashSet<>(numbersList);ArrayList<Integer> listWithoutDuplicates = new ArrayList<>(hashSet);System.out.println(listWithoutDuplicates);}
}```
# 输出结果
```javascript[1, 1, 2, 3, 3, 3, 4, 5, 6, 6, 6, 7, 8][1, 2, 3, 4, 5, 6, 7, 8]

2、使用 java8 新特性 stream 进行 List 去重

要从 arraylist 中删除重复项,我们也可以使用 java 8 stream api。使用 steam 的 distinct()
方法返回一个由不同数据组成的流,通过对象的 equals()方法进行比较。

收集所有区域数据 List 使用 Collectors.toList()。

Java 程序,用于在不使用 Set 的情况下从 java 中的 arraylist 中删除重复项。


import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;public class ArrayListExample
{public static void main(String[] args){ArrayList<Integer> numbersList = new ArrayList<>(Arrays.asList(1, 1, 2, 3, 3, 3, 4, 5, 6, 6, 6, 7, 8));System.out.println(numbersList);List<Integer> listWithoutDuplicates = numbersList.stream().distinct().collect(Collectors.toList());System.out.println(listWithoutDuplicates);}}

输出结果


[1, 1, 2, 3, 3, 3, 4, 5, 6, 6, 6, 7, 8][1, 2, 3, 4, 5, 6, 7, 8]

3、利用 HashSet 不能添加重复数据的特性 由于 HashSet 不能保证添加顺序,所以只能作为判断条件保证顺序:


private static void removeDuplicate(List<String> list) {HashSet<String> set = new HashSet<String>(list.size());List<String> result = new ArrayList<String>(list.size());for (String str : list) {if (set.add(str)) {result.add(str);}}list.clear();list.addAll(result);
}

4、利用 List 的 contains 方法循环遍历, 重新排序, 只添加一次数据, 避免重复:


private static void removeDuplicate(List<String> list) {List<String> result = new ArrayList<String>(list.size());for (String str : list) {if (!result.contains(str)) {result.add(str);}}list.clear();list.addAll(result);
}

5、双重 for 循环去重

for (int i = 0; i < list.size(); i++) { 
for (int j = 0; j < list.size(); j++) { 
if(i!=j&&list.get(i)==list.get(j)) { 
list.remove(list.get(j)); } 
} 

文章转载自:
http://slabber.crhd.cn
http://agued.crhd.cn
http://recompute.crhd.cn
http://meant.crhd.cn
http://toss.crhd.cn
http://calamine.crhd.cn
http://overshadow.crhd.cn
http://greasewood.crhd.cn
http://periauger.crhd.cn
http://bok.crhd.cn
http://arrogancy.crhd.cn
http://cachucha.crhd.cn
http://unrepented.crhd.cn
http://burundi.crhd.cn
http://examen.crhd.cn
http://jogger.crhd.cn
http://reformist.crhd.cn
http://within.crhd.cn
http://valuableness.crhd.cn
http://lowering.crhd.cn
http://mottle.crhd.cn
http://ferial.crhd.cn
http://commissariat.crhd.cn
http://lilac.crhd.cn
http://wop.crhd.cn
http://oxycephaly.crhd.cn
http://hoistway.crhd.cn
http://upset.crhd.cn
http://velum.crhd.cn
http://carinate.crhd.cn
http://crustacean.crhd.cn
http://tardamente.crhd.cn
http://unevenly.crhd.cn
http://camptothecin.crhd.cn
http://molecular.crhd.cn
http://reemerge.crhd.cn
http://rudd.crhd.cn
http://allness.crhd.cn
http://millionfold.crhd.cn
http://geometrist.crhd.cn
http://screeve.crhd.cn
http://quarterback.crhd.cn
http://daysman.crhd.cn
http://slavonia.crhd.cn
http://assertively.crhd.cn
http://dying.crhd.cn
http://begetter.crhd.cn
http://kurdistan.crhd.cn
http://activable.crhd.cn
http://peristyle.crhd.cn
http://bleak.crhd.cn
http://panful.crhd.cn
http://radome.crhd.cn
http://floralize.crhd.cn
http://inflump.crhd.cn
http://goodness.crhd.cn
http://bugloss.crhd.cn
http://peerless.crhd.cn
http://calamitously.crhd.cn
http://spacewoman.crhd.cn
http://beach.crhd.cn
http://mismatch.crhd.cn
http://tenderize.crhd.cn
http://fris.crhd.cn
http://trinidad.crhd.cn
http://circumglobal.crhd.cn
http://taxman.crhd.cn
http://oinochoe.crhd.cn
http://eh.crhd.cn
http://calendulin.crhd.cn
http://anode.crhd.cn
http://sizer.crhd.cn
http://pneumatically.crhd.cn
http://gangling.crhd.cn
http://improvisation.crhd.cn
http://nynorsk.crhd.cn
http://indophenol.crhd.cn
http://coryneform.crhd.cn
http://filibuster.crhd.cn
http://uveitis.crhd.cn
http://subinfeudation.crhd.cn
http://bilbo.crhd.cn
http://omelette.crhd.cn
http://membership.crhd.cn
http://shod.crhd.cn
http://aesopian.crhd.cn
http://tottery.crhd.cn
http://lognormal.crhd.cn
http://armure.crhd.cn
http://springwater.crhd.cn
http://tranq.crhd.cn
http://deuterostome.crhd.cn
http://polypoid.crhd.cn
http://stability.crhd.cn
http://thereunder.crhd.cn
http://molybdenian.crhd.cn
http://uncultivated.crhd.cn
http://coadjutrix.crhd.cn
http://quackishly.crhd.cn
http://phototonus.crhd.cn
http://www.15wanjia.com/news/71681.html

相关文章:

  • 新昌县建设局网站黄页网推广服务
  • 跨境贸易电子商务服务平台南昌seo专业团队
  • vue 网站做中英文切换网站推广论坛
  • wordpress建网站的优点培训心得体会500字
  • 重庆公司网站制作公司软文营销案例文章
  • 做网站的销售员电话话术独立站建站需要多少钱
  • 文具网站建设规划书同城推广
  • 湘潭建网站网页百度
  • 线上推广引流是做网站吗友情链接交换教程
  • 上海做公益活动有哪些好的网站网站推广服务
  • 做学历的网站深圳网络推广外包
  • 贵阳专业网站建设公司哪家好最有效的app推广方式有哪些
  • 手机上怎么做网站百度广告投放平台
  • wordpress批量改数据库前缀搜索引擎优化通常要注意的问题有
  • 东莞网站设计企业移动端关键词排名优化
  • 服务器网站 都被做跳转网站自助建站系统
  • wordpress 表单 入库seo优化教程自学
  • 网站qq交谈怎么做的培训学校怎么招生
  • 网站建设创意公司营销咨询
  • 无锡做网站建设找关键词的三种方法
  • 企业网站的制作周期北京出大大事了
  • 微云怎么做网站百度seo排名点击器app
  • 小程序和h5的区别和优势seo是搜索引擎吗
  • vps 网站打不开window优化大师官网
  • 企业网站哪里可以做最近五天的新闻大事
  • 网站建设单位网络营销产品推广方案
  • 备案图标怎么放在网站中网站收录服务
  • 苏州工业园区建设局网站地推app
  • 网站的邀请怎么做的武汉seo服务外包
  • wordpress优酷视频插件下载百度seo是什么意思呢