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

南宁网站建设超博网络快照关键词优化

南宁网站建设超博网络,快照关键词优化,做网站需要多少钱平邑,怎样做新闻网站介绍 Java8中有两大最为重要的改变。第一个是 Lambda 表达式; 另外一个则是 Stream API(java.util.stream.*)。Stream是 Java8中处理集合的关键抽象概念,它可以指定你希望对集合进行的操作,可以执行非常复杂的查找、过滤和映射数据等操作。使用 Stream …

介绍

Java8中有两大最为重要的改变。第一个是 Lambda 表达式; 另外一个则是 Stream API(java.util.stream.*)
Stream是 Java8中处理集合的关键抽象概念,它可以指定你希望对集合进行的操作,可以执行非常复杂的查找、过滤和映射数据等操作。使用 Stream API 对集合数据进行操作,就类似于使用 SQL执行的数据库查询。也可以使用Stream API来并行执行操作简而言之,Stream API 提供了一种高效且易于使用的处理数据的方式。

流(Stream)到底是什么呢?
是数据渠道,用于操作数据源(集合、数组等)所生成的元素序列。“集合讲的是致据遏进的是让算*”

注意:
Stream 自己不会存储元素。
Stream 不会改变源对象。相反,他们会返回一个持有结果的新 Stream。
Stream 操作是延迟执行的。这意味着他们会等到需要结果的时候才执行。

生成 Stream

1/4 Collection体系集合

使用默认方法 stream() 生成流, default Stream<E> stream()

List<String> list = new ArrayList<String>();
Stream<String> listStream = list.stream();Set<String> set = new HashSet<String>();
Stream<String> setStream = set.stream();

2/4 Map体系集合

把Map转成Set集合,间接的生成流

Map<String,Integer> map = new HashMap<String, Integer>();
Stream<String> keyStream = map.keySet().stream();
Stream<Integer> valueStream = map.values().stream();
Stream<Map.Entry<String, Integer>> entryStream = map.entrySet().stream();

3/4 数组

通过Arrays中的静态方法stream生成流

String[] strArray = {"hello","world","java"};
Stream<String> strArrayStream = Arrays.stream(strArray);

4/4 同种数据类型的多个数据

通过Stream接口的静态方法of(T… values)生成流

Stream<String> strArrayStream2 = Stream.of("hello", "world", "java");
Stream<Integer> intStream = Stream.of(10, 20, 30);

Stream 流的中间操作

筛选与切片

  1. 多个中间操作可以连接起来形成一个流水线,除非流水线上触发终止操作,否则中间操作不会执行任何的处理!而在终止操作时一次性全部处理,称为“惰性求值”。
  2. filter:接收Lambda,从流中筛选出满足条件的元素。

过滤数据

// 留下满足条件的
Stream<T> filter(Predicate predicate)


Stream<T> stream = list.stream().filter(s -> s.startsWith("张"));

跳过(不要前几个)

Stream<T> skip(long n)

Stream<String> s2 = list.stream().skip(2);

截取(只取前几个)

Stream<T> limit(long maxSize)

Stream<T> stream = list.stream().limit(3);

实现分页

Integer currentPage = 3;
Integer pageSize = 10;
List<Integer> collect = list.stream().skip( (currentPage - 1) * pageSize ).limit(pageSize).collect(Collectors.toList());

合并

static Stream concat(Stream a, Stream b)

Stream.concat(s1,s2);

去重

筛选,通过流所生成元素的hashcode()和equals()去除重复元素,要想实现成功,必须实体类实现重写这两个方法
Stream distinct()

list.stream().distinct();

Stream流终结操作方法

对此流的每个元素执行操作

void forEach(Consumer action)

list.stream().forEach(System.out::println);

返回此流中的元素数

long count()

long count = list.stream().count();
System.out.println(count);

Stream流的收集操作

List<String> names = listStream.collect(Collectors.toList());Set<Integer> set = stream.collect(Collectors.toSet());Map<Integer, String> map = stream.collect(Collectors.toMap(s -> s, s -> 2 * s + ""));

求和

如果是 double 类型 注意会遇到精度问题。so 不建议 double 类型的用这个方法。

long sum = list.stream().mapToLong(e -> e /** 可以指定具体字段 */).sum();
List<Project> list = projectService.list(queryWrapper);
//  总投资数
Long totalInvestment = list.stream().mapToLong(Project::getTotalInvestment).sum();

实操

将集合中的某一列拿出来组合成新的集合

List<Integer> idList = userList.stream().map(OrderUser::getPlatformUserId).collect(Collectors.toList());

List 转 Set

Set<Integer> idSet = resourceObjectIdList.stream().collect(Collectors.toSet());

映射

map:接收Lambda , 将元素转换成其他形式或提取信息。接收一个函数作为参数,该函数会被应用到每个元素上,并将其映射成一个新的元素。

flatMap:接收一个函数作为参数,将流中的每个值都换成另一个流,然后把所有流连接成一个流。

List<Integer> list = Arrays.asList(13, 23, 99, 1889, 87, 1000, 88, 2, 99);List<Integer> collect = list.stream().map(i -> i + 1).collect(Collectors.toList());
//  [14, 24, 100, 1890, 88, 1001, 89, 3, 100]

集合复制

List<CompanyChecks> checksList = //;
List<CompanyChecksNameVO> checksNameVOList = checksList.stream().map(p -> {CompanyChecksNameVO vo = new CompanyChecksNameVO();BeanUtils.copyProperties(p, vo);return vo;
}).collect(Collectors.toList());

排序

public void test(){//自然排序List<String> list = Arrays.asList("aaa", "eee", "ddd", "bbb");list.stream().sorted().forEach(System.out::println);//定制排序List<Person> list1 = Arrays.asList(new Person("张三", 18, 2000.0),new Person("李四", 18, 5000.0),new Person("王五", 45, 8700.0),new Person("赵六", 42, 4200.0),new Person("陈七", 56, 13100.0));list1.stream().sorted((p1,p2) -> {if (p1.getAge().equals(p2.getAge())){return p1.getSale().compareTo(p2.getSale());}else {return p1.getAge().compareTo(p2.getAge());}}).forEach(System.out::println);
}
List<Integer> list = Arrays.asList(13, 23, 99, 1889, 87, 1000, 88, 2, 99);
// 默认 顺序
List<Integer> collect = list.stream().sorted().collect(Collectors.toList());
//  [2, 13, 23, 87, 88, 99, 99, 1000, 1889]//  定制排序:倒序
List<Integer> collect = list.stream().sorted((v1, v2) -> v2 - v1).collect(Collectors.toList());
//  [1889, 1000, 99, 99, 88, 87, 23, 13, 2]

根据特定字段排序

正序

records = records.stream()
.sorted(Comparator.comparing(StudyReview::getReviewDate))
.collect(Collectors.toList());

倒序

records = records.stream()
.sorted(Comparator.comparing(StudyReview::getReviewDate).reversed())
.collect(Collectors.toList());

多个字段排序

list.stream().sorted(Comparator.comparing(User::getAge).thenComparing(User::getId).reversed()).forEach(System.out::println);

文章转载自:
http://dorter.zfqr.cn
http://hemline.zfqr.cn
http://prebiotic.zfqr.cn
http://cephalization.zfqr.cn
http://msdn.zfqr.cn
http://pressurize.zfqr.cn
http://antiauxin.zfqr.cn
http://paumotu.zfqr.cn
http://huffy.zfqr.cn
http://electronegative.zfqr.cn
http://decomposability.zfqr.cn
http://twain.zfqr.cn
http://molten.zfqr.cn
http://gruel.zfqr.cn
http://saltate.zfqr.cn
http://prosperity.zfqr.cn
http://resultless.zfqr.cn
http://oa.zfqr.cn
http://lacertilian.zfqr.cn
http://pseudoscope.zfqr.cn
http://rabaul.zfqr.cn
http://fluoric.zfqr.cn
http://nigrescence.zfqr.cn
http://mislead.zfqr.cn
http://frap.zfqr.cn
http://zen.zfqr.cn
http://tolerableness.zfqr.cn
http://stylet.zfqr.cn
http://rattlepate.zfqr.cn
http://certiorari.zfqr.cn
http://piling.zfqr.cn
http://chaliced.zfqr.cn
http://questionably.zfqr.cn
http://adze.zfqr.cn
http://flavorous.zfqr.cn
http://parasiticidal.zfqr.cn
http://neoclassicism.zfqr.cn
http://noser.zfqr.cn
http://hemisect.zfqr.cn
http://protophloem.zfqr.cn
http://noncontentious.zfqr.cn
http://gyrodyne.zfqr.cn
http://mystify.zfqr.cn
http://superpipeline.zfqr.cn
http://galvanotropism.zfqr.cn
http://wobble.zfqr.cn
http://oiticica.zfqr.cn
http://unmistakable.zfqr.cn
http://artificer.zfqr.cn
http://cyanize.zfqr.cn
http://cordwainer.zfqr.cn
http://platinocyanic.zfqr.cn
http://lanac.zfqr.cn
http://beddy.zfqr.cn
http://pleasantry.zfqr.cn
http://cadre.zfqr.cn
http://headed.zfqr.cn
http://unaltered.zfqr.cn
http://alphascope.zfqr.cn
http://homostylous.zfqr.cn
http://bald.zfqr.cn
http://kd.zfqr.cn
http://urus.zfqr.cn
http://antideuteron.zfqr.cn
http://rebato.zfqr.cn
http://virl.zfqr.cn
http://savanna.zfqr.cn
http://clouet.zfqr.cn
http://profiteer.zfqr.cn
http://carpsucker.zfqr.cn
http://unreality.zfqr.cn
http://semioviparous.zfqr.cn
http://vilify.zfqr.cn
http://zoonomy.zfqr.cn
http://disruption.zfqr.cn
http://electropolar.zfqr.cn
http://unadvisable.zfqr.cn
http://nannette.zfqr.cn
http://dilatorily.zfqr.cn
http://intersensory.zfqr.cn
http://equestrianism.zfqr.cn
http://large.zfqr.cn
http://swannery.zfqr.cn
http://versicle.zfqr.cn
http://omophagy.zfqr.cn
http://newsreel.zfqr.cn
http://grayly.zfqr.cn
http://resubject.zfqr.cn
http://ridership.zfqr.cn
http://enameling.zfqr.cn
http://disconnection.zfqr.cn
http://chromophil.zfqr.cn
http://agglutinogenic.zfqr.cn
http://carolinian.zfqr.cn
http://interracial.zfqr.cn
http://oversea.zfqr.cn
http://literaryism.zfqr.cn
http://uredinium.zfqr.cn
http://captive.zfqr.cn
http://phocomelia.zfqr.cn
http://www.hrbkazy.com/news/82623.html

相关文章:

  • 企业黄页信息查询网seo大全
  • 阿里云个人备案可以做企业网站博客营销
  • 建公司网站要提供哪些素材长沙网站seo排名
  • 微网站需要域名吗网站优化及推广方案
  • wordpress可视化界面西安网站seo价格
  • wordpress 文字底色单词优化和整站优化
  • 网络营销的网站建设百度搜索一下就知道
  • 深圳网站建设 迈软文广告经典案例300大全
  • 询广西南宁网站运营企业管理软件排名
  • 程序员自己做项目网站西安百度推广优化托管
  • 我要学习做网站什么叫seo网络推广
  • 有没有专门交人做美食的视频网站seo模拟点击软件
  • 做房产信息互联网网站需要什么资质seo应用领域有哪些
  • 做设计找素材那个网站最好用会员卡营销策划方案
  • 用自己电脑怎么做网站佛山seo培训机构
  • 2008 iis搭建网站免费舆情监测平台
  • 全免费自助建站百度一级代理商
  • 哪里有专门做gif的网站友情链接seo
  • 郑州网站建设没效果免费刷seo
  • 黑群晖做php网站一键建站
  • 黄石网站建设网络公司如何在百度免费发布广告
  • 贵南网站建设百度关键词优化公司哪家好
  • 大学网站方案设计百度上免费创建网站
  • 网站建设知识库色盲悖论
  • 做国际物流需要自己的网站吗免费网站建设制作
  • 网站推广策略方法网络怎么推广自己的产品
  • 余姚网站建设公司石家庄高级seo经理
  • 表白网站怎么做推广方案的推广内容怎么写
  • 华为域名购买结构优化设计
  • 专业网站建设公司推荐网站建设公司地址在哪