高效 告别996,开启java高效编程之门 3-7实战:常用中间操作演示之:过滤/映射/扁平化 filter/map/flagMap
2021-02-21 00:18
标签:alibaba port date 注意 执行 转换 返回 out 变量 filter方法的使用 map方法的使用 flatMap方法的使用 forEach方法的使用 map的作用很容易理解就是对rdd之中的元素进行逐一进行函数操作映射为另外一个rdd。 flatMap的操作是将函数应用于rdd之中的每一个元素,将返回的迭代器的所有内容构成新的rdd。通常用来切分单词,可用来单词计数 打印日志: 打印日志: 打印日志: 高效 告别996,开启java高效编程之门 3-7实战:常用中间操作演示之:过滤/映射/扁平化 filter/map/flagMap 标签:alibaba port date 注意 执行 转换 返回 out 变量 原文地址:https://www.cnblogs.com/1446358788-qq/p/12678718.html1 重点
2 map和flatMap的区别:
3 实战演示之过滤(filter):
package com.imooc.zhangxiaoxi.stream;
import com.alibaba.fastjson.JSONObject;
import com.imooc.zhangxiaoxi.lambda.cart.CartService;
import com.imooc.zhangxiaoxi.lambda.cart.Sku;
import com.imooc.zhangxiaoxi.lambda.cart.SkuCategoryEnum;
import org.junit.Before;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
/**
* StreamOperator
* 作用:演示各种流的操作
* @author 魏豆豆
* @date 2020/4/11
*/
public class StreamOperator {
private List
{
"skuCategory":"BOOKS",
"skuId":2020003,
"skuName":"人生的枷锁",
"skuPrice":30.0,
"totalNum":1,
"totalPrice":30.0
}
{
"skuCategory":"BOOKS",
"skuId":2020004,
"skuName":"老人与海",
"skuPrice":20.0,
"totalNum":1,
"totalPrice":20.0
}
{
"skuCategory":"BOOKS",
"skuId":2020005,
"skuName":"剑指高效编程",
"skuPrice":288.0,
"totalNum":1,
"totalPrice":288.0
}
Process finished with exit code 0
4 实战演示之映射(map):
package com.imooc.zhangxiaoxi.stream;
import com.alibaba.fastjson.JSONObject;
import com.imooc.zhangxiaoxi.lambda.cart.CartService;
import com.imooc.zhangxiaoxi.lambda.cart.Sku;
import com.imooc.zhangxiaoxi.lambda.cart.SkuCategoryEnum;
import org.junit.Before;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
/**
* StreamOperator
* 作用:演示各种流的操作
* @author 魏豆豆
* @date 2020/4/11
*/
public class StreamOperator {
private List
"无人机"
"T-shirt"
"人生的枷锁"
"老人与海"
"剑指高效编程"
"大头皮鞋"
"杠铃"
"ThinkPad"
Process finished with exit code 0
5 实战演示之扁平化(filterMap):
package com.imooc.zhangxiaoxi.stream;
import com.alibaba.fastjson.JSONObject;
import com.imooc.zhangxiaoxi.lambda.cart.CartService;
import com.imooc.zhangxiaoxi.lambda.cart.Sku;
import com.imooc.zhangxiaoxi.lambda.cart.SkuCategoryEnum;
import org.junit.Before;
import org.junit.Test;
import java.util.Arrays;
import java.util.List;
/**
* StreamOperator
* 作用:演示各种流的操作
* @author 魏豆豆
* @date 2020/4/11
*/
public class StreamOperator {
private List
"无"
"人"
"机"
"T"
"-"
"s"
"h"
"i"
"r"
"t"
"人"
"生"
"的"
"枷"
"锁"
"老"
"人"
"与"
"海"
"剑"
"指"
"高"
"效"
"编"
"程"
"大"
"头"
"皮"
"鞋"
"杠"
"铃"
"T"
"h"
"i"
"n"
"k"
"P"
"a"
"d"
Process finished with exit code 0
文章标题:高效 告别996,开启java高效编程之门 3-7实战:常用中间操作演示之:过滤/映射/扁平化 filter/map/flagMap
文章链接:http://soscw.com/index.php/essay/58209.html