一、Collector的引入      

1)Collector的聚合作用前面已经使用过,将list.stream后的一系列操作之后再返回list。

2)Collector的引入,通过需求:将绿色的Apple放在一个list,黄色的Apple放在一个list

代码例子:

 package com.cy.java8;

 import java.util.*;
import java.util.stream.Collectors; public class CollectorIntroduce { public static void main(String[] args) {
List<Apple> list = Arrays.asList(new Apple("green", 150),
new Apple("yellow", 120),
new Apple("green", 170),
new Apple("green", 150),
new Apple("yellow", 120),
new Apple("green", 170) ); //Collector的聚合作用
List<Apple> greenList = list.stream().filter(a -> a.getColor().equals("green")).collect(Collectors.toList());
System.out.println(greenList); Map<String, List<Apple>> result1 = groupByNormal(list);
System.out.println(result1); Map<String, List<Apple>> result2 = groupByFunction(list);
System.out.println(result2); //Collector的groupBy
Map<String, List<Apple>> result3 = groupByCollector(list);
System.out.println(result3);
} /**
* 需求:将绿色的放在一个list,黄色的放在一个list
* 以前的写法
*/
private static Map<String, List<Apple>> groupByNormal(List<Apple> apples){
Map<String, List<Apple>> map = new HashMap<>(); for(Apple a : apples){
List<Apple> list = map.get(a.getColor());
if(list == null){
list = new ArrayList<>();
map.put(a.getColor(), list);
}
list.add(a);
} return map;
} /**
* 需求:将绿色的放在一个list,黄色的放在一个list
* 使用FunctionInterface的方法
* 虽然去掉了判断null的操作,但是也还是非常啰嗦,不够精简
*/
private static Map<String, List<Apple>> groupByFunction(List<Apple> apples){
Map<String, List<Apple>> map = new HashMap<>(); apples.stream().forEach(a -> {
List<Apple> colorList = Optional.ofNullable(map.get(a.getColor())).orElseGet(() -> {
List<Apple> list = new ArrayList<>();
map.put(a.getColor(), list);
return list;
});
colorList.add(a);
}); return map;
} /**
* 需求:将绿色的放在一个list,黄色的放在一个list
* 使用Collector
*/
private static Map<String, List<Apple>> groupByCollector(List<Apple> apples){
return apples.stream().collect(Collectors.groupingBy(Apple::getColor));
}
}

打印结果:

[Apple(color=green, weight=150), Apple(color=green, weight=170), Apple(color=green, weight=150), Apple(color=green, weight=170)]
{green=[Apple(color=green, weight=150), Apple(color=green, weight=170), Apple(color=green, weight=150), Apple(color=green, weight=170)], yellow=[Apple(color=yellow, weight=120), Apple(color=yellow, weight=120)]}
{green=[Apple(color=green, weight=150), Apple(color=green, weight=170), Apple(color=green, weight=150), Apple(color=green, weight=170)], yellow=[Apple(color=yellow, weight=120), Apple(color=yellow, weight=120)]}
{green=[Apple(color=green, weight=150), Apple(color=green, weight=170), Apple(color=green, weight=150), Apple(color=green, weight=170)], yellow=[Apple(color=yellow, weight=120), Apple(color=yellow, weight=120)]}

二、Collectors的API介绍和使用  

averagingDouble;

averagingInt;

averagingLong;

collectingAndThen;

counting;

groupingBy;

summarizingInt;

代码例子:

 package com.cy.java8;

 import java.util.*;
import java.util.stream.Collectors; public class CollectorsAction {
private final static List<Dish> menu = Arrays.asList(
new Dish("pork", false, 800, Dish.Type.MEAT),
new Dish("beef", false, 700, Dish.Type.MEAT),
new Dish("chicken", false, 400, Dish.Type.MEAT),
new Dish("french fries", true, 530, Dish.Type.OTHER),
new Dish("rice", true, 350, Dish.Type.OTHER),
new Dish("season fruit", true, 120, Dish.Type.OTHER),
new Dish("pizza", true, 550, Dish.Type.OTHER),
new Dish("prawns", false, 300, Dish.Type.FISH),
new Dish("salmon", false, 450, Dish.Type.FISH)); public static void main(String[] args) {
testAveragingDouble();
testAveragingInt();
testCollectingAndThen();
testCounting();
testGroupingByFunction();
testGroupingByFunctionAndCollector();
testGroupingByFunctionAndSupplierAndCollector();
testSummarizingInt();
} /**
* 计算menu中食物们卡路里的平均数
*/
private static void testAveragingDouble(){
System.out.println("testAveragingDouble");
Optional.ofNullable(menu.stream().collect(Collectors.averagingDouble(Dish::getCalories)))
.ifPresent(System.out::println);
} /**
* testAveragingInt和testAveragingLong的返回值类型也是Double,和上面类似
*/
private static void testAveragingInt(){
System.out.println("testAveragingInt");
Optional.ofNullable(menu.stream().collect(Collectors.averagingInt(Dish::getCalories)))
.ifPresent(System.out::println);
} private static void testCollectingAndThen(){
System.out.println("testCollectingAndThen");
Optional.ofNullable(menu.stream().collect(Collectors.collectingAndThen(Collectors.averagingInt(Dish::getCalories), v-> "The Average Calories is " + v)))
.ifPresent(System.out::println); } /**
* 计算list<Dish>的count
*/
private static void testCounting(){
System.out.println("testCounting");
Long count = menu.stream().collect(Collectors.counting());
System.out.println(count);
} /**
* 将menu按照type类型分组
*/
private static void testGroupingByFunction(){
System.out.println("testGroupingByFunction");
Map<Dish.Type, List<Dish>> map = menu.stream().collect(Collectors.groupingBy(dish -> dish.getType()));
System.out.println(map);
} /**
* 将menu按照type分组,并计算每个组元素数量
*/
private static void testGroupingByFunctionAndCollector(){
System.out.println("testGroupingByFunctionAndCollector");
Map<Dish.Type, Long> map1 = menu.stream().collect(Collectors.groupingBy(dish -> dish.getType(), Collectors.counting()));
System.out.println(map1); //每个类型卡路里的平均值
Map<Dish.Type, Double> map2 = menu.stream().collect(Collectors.groupingBy(dish -> dish.getType(), Collectors.averagingInt(Dish::getCalories)));
System.out.println(map2);
} /**
* Supplier mapFactory,第2个参数,可以指定传入什么类型的map
*/
private static void testGroupingByFunctionAndSupplierAndCollector(){
System.out.println("testGroupingByFunctionAndSupplierAndCollector");
Map<Dish.Type, Double> map = menu.stream().collect(Collectors.groupingBy(Dish::getType, TreeMap::new, Collectors.averagingInt(Dish::getCalories)));
System.out.println(map.getClass());
System.out.println(map);
} /**
* 将菜单menu按照卡路里进行汇总
*/
private static void testSummarizingInt(){
System.out.println("testSummarizingInt");
IntSummaryStatistics result = menu.stream().collect(Collectors.summarizingInt(Dish::getCalories));
System.out.println(result);
}
}

打印结果:

testAveragingDouble
466.6666666666667
testAveragingInt
466.6666666666667
testCollectingAndThen
The Average Calories is 466.6666666666667
testCounting
9
testGroupingByFunction
{MEAT=[Dish{name='pork', vegetarian=false, calories=800, type=MEAT}, Dish{name='beef', vegetarian=false, calories=700, type=MEAT}, Dish{name='chicken', vegetarian=false, calories=400, type=MEAT}], OTHER=[Dish{name='french fries', vegetarian=true, calories=530, type=OTHER}, Dish{name='rice', vegetarian=true, calories=350, type=OTHER}, Dish{name='season fruit', vegetarian=true, calories=120, type=OTHER}, Dish{name='pizza', vegetarian=true, calories=550, type=OTHER}], FISH=[Dish{name='prawns', vegetarian=false, calories=300, type=FISH}, Dish{name='salmon', vegetarian=false, calories=450, type=FISH}]}
testGroupingByFunctionAndCollector
{MEAT=3, OTHER=4, FISH=2}
{MEAT=633.3333333333334, OTHER=387.5, FISH=375.0}
testGroupingByFunctionAndSupplierAndCollector
class java.util.TreeMap
{MEAT=633.3333333333334, FISH=375.0, OTHER=387.5}
testSummarizingInt
IntSummaryStatistics{count=9, sum=4200, min=120, average=466.666667, max=800}

三、Collectors的API介绍和使用2  

GroupingByConcurrent;

joining;

mapping;

maxBy

代码举例如下:

 package com.cy.java8;

 import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.stream.Collectors;
import static com.cy.java8.CollectorsAction.menu; public class CollectorsAction2 { public static void main(String[] args) {
testGroupingByConcurrentWithFunction();
testGroupingByConcurrentWithFunctionAndCollector();
testGroupingByConcurrentWithFunctionAndSupplierAndCollector();
testJoining();
testMapping();
testMaxBy();
} /**
* 按食物类型分类
*/
private static void testGroupingByConcurrentWithFunction() {
System.out.println("testGroupingByConcurrentWithFunction");
ConcurrentMap<Dish.Type, List<Dish>> map = menu.stream().collect(Collectors.groupingByConcurrent(Dish::getType));
System.out.println(map.getClass());
System.out.println(map);
} /**
* 每类食物类型下面 卡路里平均值
*/
private static void testGroupingByConcurrentWithFunctionAndCollector() {
System.out.println("testGroupingByConcurrentWithFunctionAndCollector");
ConcurrentMap<Dish.Type, Double> map = menu.stream().collect(Collectors.groupingByConcurrent(Dish::getType, Collectors.averagingInt(Dish::getCalories)));
System.out.println(map);
} private static void testGroupingByConcurrentWithFunctionAndSupplierAndCollector() {
System.out.println("testGroupingByConcurrentWithFunctionAndCollector");
ConcurrentMap<Dish.Type, Double> map = menu.stream().collect(Collectors.groupingByConcurrent(Dish::getType, ConcurrentSkipListMap::new, Collectors.averagingInt(Dish::getCalories)));
System.out.println(map.getClass());
System.out.println(map);
} /**
* joining: 对stream里面的一些值进行连接
* 对食物的名字进行连接
*/
private static void testJoining() {
System.out.println("testJoining");
String s = menu.stream().map(Dish::getName).collect(Collectors.joining(",", "Names[", "]"));
System.out.println(s);
} /**
* 用一个mapping function在汇聚之前,将接受Dish的集合适用于接受DishName的集合
*/
private static void testMapping() {
System.out.println("testMapping");
String s = menu.stream().collect(Collectors.mapping(d -> d.getName(), Collectors.joining(",", "Names[", "]")));
System.out.println(s);
} /**
* 找出热量最大的食物
*/
private static void testMaxBy(){
System.out.println("testMaxBy");
Optional<Dish> maxCaloriesOptional = menu.stream().collect(Collectors.maxBy(Comparator.comparingInt(Dish::getCalories)));
maxCaloriesOptional.ifPresent(System.out::println);
} }

打印结果:

testGroupingByConcurrentWithFunction
class java.util.concurrent.ConcurrentHashMap
{FISH=[Dish{name='prawns', vegetarian=false, calories=300, type=FISH}, Dish{name='salmon', vegetarian=false, calories=450, type=FISH}], MEAT=[Dish{name='pork', vegetarian=false, calories=800, type=MEAT}, Dish{name='beef', vegetarian=false, calories=700, type=MEAT}, Dish{name='chicken', vegetarian=false, calories=400, type=MEAT}], OTHER=[Dish{name='french fries', vegetarian=true, calories=530, type=OTHER}, Dish{name='rice', vegetarian=true, calories=350, type=OTHER}, Dish{name='season fruit', vegetarian=true, calories=120, type=OTHER}, Dish{name='pizza', vegetarian=true, calories=550, type=OTHER}]}
testGroupingByConcurrentWithFunctionAndCollector
{FISH=375.0, MEAT=633.3333333333334, OTHER=387.5}
testGroupingByConcurrentWithFunctionAndCollector
class java.util.concurrent.ConcurrentSkipListMap
{MEAT=633.3333333333334, FISH=375.0, OTHER=387.5}
testJoining
Names[pork,beef,chicken,french fries,rice,season fruit,pizza,prawns,salmon]
testMapping
Names[pork,beef,chicken,french fries,rice,season fruit,pizza,prawns,salmon]
testMaxBy
Dish{name='pork', vegetarian=false, calories=800, type=MEAT}

四、Collectors的API介绍和使用3

partitioningBy

reduce

summarizingDouble

summarizingLong

summarizingInt

代码举例如下:

 package com.cy.java8;

 import java.util.*;
import java.util.function.BinaryOperator;
import java.util.stream.Collectors; import static com.cy.java8.CollectorsAction.menu; public class CollectorsAction3 { public static void main(String[] args) {
testPartitioningByWithPredicate();
testPartitioningByWithPredicateAndCollector();
testReducingBinaryOperator();
testReducingBinaryOperatorAndIdentity();
testReducingBinaryOperatorAndIdentityAndFunction();
testSummarizingDouble();
testSummarizingLong();
testSummarizingInt();
} /**
* 利用partitioningBy把menu中素食类和非素食类的分开
*/
private static void testPartitioningByWithPredicate() {
System.out.println("testPartitioningByPredicate");
Map<Boolean, List<Dish>> map = menu.stream().collect(Collectors.partitioningBy(Dish::isVegetarian));
System.out.println(map);
} /**
* 把素食类和非素食类分开,计算平均卡路里
*/
private static void testPartitioningByWithPredicateAndCollector() {
System.out.println("testPartitioningByWithPredicateAndCollector");
Map<Boolean, Double> map = menu.stream().collect(Collectors.partitioningBy(Dish::isVegetarian, Collectors.averagingInt(Dish::getCalories)));
System.out.println(map);
System.out.println(map.get(true));
} /**
* 找出menu中热量最大的dish
*/
private static void testReducingBinaryOperator() {
System.out.println("testReducingBinaryOperator");
//以前这么写
Optional<Dish> optional = menu.stream().reduce((dish1, dish2) -> dish1.getCalories() > dish2.getCalories() ? dish1 : dish2);
optional.ifPresent(System.out::println); //Collectors.reducing
Optional<Dish> optional2 = menu.stream().collect(Collectors.reducing(BinaryOperator.maxBy(Comparator.comparingInt(Dish::getCalories))));
optional2.ifPresent(System.out::println); Optional<Dish> optional3 = menu.stream().collect(Collectors.reducing((dish1, dish2) -> dish1.getCalories() > dish2.getCalories() ? dish1 : dish2));
optional3.ifPresent(System.out::println);
} /**
* 计算所有卡路里和
*/
private static void testReducingBinaryOperatorAndIdentity() {
System.out.println("testReducingBinaryOperatorAndIdentity");
//以前这么写
Integer totalCalories1 = menu.stream().map(Dish::getCalories).reduce(0, Integer::sum);
System.out.println(totalCalories1); //Collectors.reducing
Integer totalCalories2 = menu.stream().map(Dish::getCalories).collect(Collectors.reducing(0, Integer::sum));
System.out.println(totalCalories2);
} private static void testReducingBinaryOperatorAndIdentityAndFunction() {
System.out.println("testReducingBinaryOperatorAndIdentityAndFunction");
Integer result = menu.stream().collect(Collectors.reducing(0, Dish::getCalories, (d1, d2) -> d1 + d2));
System.out.println(result);
} private static void testSummarizingDouble(){
System.out.println("testSummarizingDouble");
DoubleSummaryStatistics result = menu.stream().collect(Collectors.summarizingDouble(Dish::getCalories));
System.out.println(result);
} private static void testSummarizingLong(){
System.out.println("testSummarizingLong");
LongSummaryStatistics result = menu.stream().collect(Collectors.summarizingLong(Dish::getCalories));
System.out.println(result);
} private static void testSummarizingInt(){
System.out.println("testSummarizingInt");
IntSummaryStatistics result = menu.stream().collect(Collectors.summarizingInt(Dish::getCalories));
System.out.println(result);
}
}

打印结果:

testPartitioningByPredicate
{false=[Dish{name='pork', vegetarian=false, calories=800, type=MEAT}, Dish{name='beef', vegetarian=false, calories=700, type=MEAT}, Dish{name='chicken', vegetarian=false, calories=400, type=MEAT}, Dish{name='prawns', vegetarian=false, calories=300, type=FISH}, Dish{name='salmon', vegetarian=false, calories=450, type=FISH}], true=[Dish{name='french fries', vegetarian=true, calories=530, type=OTHER}, Dish{name='rice', vegetarian=true, calories=350, type=OTHER}, Dish{name='season fruit', vegetarian=true, calories=120, type=OTHER}, Dish{name='pizza', vegetarian=true, calories=550, type=OTHER}]}
testPartitioningByWithPredicateAndCollector
{false=530.0, true=387.5}
387.5
testReducingBinaryOperator
Dish{name='pork', vegetarian=false, calories=800, type=MEAT}
Dish{name='pork', vegetarian=false, calories=800, type=MEAT}
Dish{name='pork', vegetarian=false, calories=800, type=MEAT}
testReducingBinaryOperatorAndIdentity
4200
4200
testReducingBinaryOperatorAndIdentityAndFunction
4200
testSummarizingDouble
DoubleSummaryStatistics{count=9, sum=4200.000000, min=120.000000, average=466.666667, max=800.000000}
testSummarizingLong
LongSummaryStatistics{count=9, sum=4200, min=120, average=466.666667, max=800}
testSummarizingInt
IntSummaryStatistics{count=9, sum=4200, min=120, average=466.666667, max=800}

  

五、Collectors的API介绍和使用4

summingDouble

summingLong

summingInt

toCollection

toConcurrentMap

toMap

toList

toSet

代码举例如下:

 package com.cy.java8;

 import java.util.LinkedList;
import java.util.List;
import java.util.Set;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.ConcurrentSkipListMap;
import java.util.stream.Collectors;
import static com.cy.java8.CollectorsAction.menu; public class CollectorsAction4 { public static void main(String[] args) {
testSummingDouble();
testToCollection();
testToConcurrentMap();
testToConcurrentMapAndBinaryOperator();
testToConcurrentMapAndBinaryOperatorAndSupplier();
testToList();
testToSet();
} /**
* 计算卡路里总和
*/
private static void testSummingDouble(){
System.out.println("testSummingDouble--------------");
//以前的写法
double sum = menu.stream().map(Dish::getCalories).mapToDouble(Integer::doubleValue).sum();
System.out.println(sum); //Collectors.summingDouble
Double sum2 = menu.stream().collect(Collectors.summingDouble(Dish::getCalories));
System.out.println(sum2);
} private static void testToCollection(){
System.out.println("testToCollection--------------");
LinkedList<Dish> list = menu.stream().filter(dish -> dish.getCalories() > 600).collect(Collectors.toCollection(LinkedList::new));
System.out.println(list);
} private static void testToConcurrentMap(){
System.out.println("testToConcurrentMap--------------");
ConcurrentMap<String, Integer> map = menu.stream().filter(dish -> dish.getCalories() > 600).collect(Collectors.toConcurrentMap(d -> d.getName(), d -> d.getCalories()));
System.out.println(map);
} /**
* Type : total
* 将menu转化为,key是type,value是这个type下有多少个,这样的map
*/
private static void testToConcurrentMapAndBinaryOperator(){
System.out.println("testToConcurrentMapAndBinaryOperator--------------");
ConcurrentMap<Dish.Type, Integer> map = menu.stream().collect(Collectors.toConcurrentMap(Dish::getType, d -> 1, (v1, v2) -> v1 + v2));
System.out.println(map.getClass());
System.out.println(map);
} private static void testToConcurrentMapAndBinaryOperatorAndSupplier(){
System.out.println("testToConcurrentMapAndBinaryOperatorAndSupplier--------------");
ConcurrentSkipListMap<Dish.Type, Integer> map = menu.stream().collect(Collectors.toConcurrentMap(Dish::getType, d -> 1, (v1, v2) -> v1 + v2, ConcurrentSkipListMap::new));
System.out.println(map.getClass());
System.out.println(map);
} private static void testToList() {
System.out.println("testToList--------------");
List<Dish> list = menu.stream().filter(Dish::isVegetarian).collect(Collectors.toList());
System.out.println(list.getClass());
System.out.println(list);
} /**
* 返回值类型为集合HashSet,里面的值不能重复,根据hashCode和equals做的判断
*/
private static void testToSet() {
System.out.println("testToSet--------------");
Set<Dish> set = menu.stream().filter(Dish::isVegetarian).collect(Collectors.toSet());
System.out.println(set.getClass());
System.out.println(set);
} /**
* toMap : 略
* toMap 和上面的 toConcurrentMap用法是一样的,只不过返回的是HashMap
*/
}

打印结果:

testSummingDouble--------------
4200.0
4200.0
testToCollection--------------
[Dish{name='pork', vegetarian=false, calories=800, type=MEAT}, Dish{name='beef', vegetarian=false, calories=700, type=MEAT}]
testToConcurrentMap--------------
{beef=700, pork=800}
testToConcurrentMapAndBinaryOperator--------------
class java.util.concurrent.ConcurrentHashMap
{OTHER=4, FISH=2, MEAT=3}
testToConcurrentMapAndBinaryOperatorAndSupplier--------------
class java.util.concurrent.ConcurrentSkipListMap
{MEAT=3, FISH=2, OTHER=4}
testToList--------------
class java.util.ArrayList
[Dish{name='french fries', vegetarian=true, calories=530, type=OTHER}, Dish{name='rice', vegetarian=true, calories=350, type=OTHER}, Dish{name='season fruit', vegetarian=true, calories=120, type=OTHER}, Dish{name='pizza', vegetarian=true, calories=550, type=OTHER}]
testToSet--------------
class java.util.HashSet
[Dish{name='rice', vegetarian=true, calories=350, type=OTHER}, Dish{name='pizza', vegetarian=true, calories=550, type=OTHER}, Dish{name='season fruit', vegetarian=true, calories=120, type=OTHER}, Dish{name='french fries', vegetarian=true, calories=530, type=OTHER}]

  

-----

Collector的使用的更多相关文章

  1. The The Garbage-First (G1) collector since Oracle JDK 7 update 4 and later releases

    Refer to http://www.oracle.com/technetwork/tutorials/tutorials-1876574.html for detail. 一些内容复制到这儿 Th ...

  2. hdu 2602 Bone Collector(01背包)模板

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...

  3. Jmeter plugin jp@gc - PerfMon Metrics Collector

    Jmeter由于是开源工具,所以目前有很多插件可以供使用,最简单的方法是先把Plugin Manager安装了 下载地址:https://jmeter-plugins.org/wiki/Plugins ...

  4. Spring AOP 开发中遇到问题:Caused by: java.lang.IllegalArgumentException: warning no match for this type name: com.xxx.collector.service.impl.XxxServiceImpl [Xlint:invalidAbsoluteTypeName]

    在网上找了很多,都不是我想要的,后来发现是我在springaop注解的时候 写错了类名导致的这个问题 @Pointcut("execution(* com.xxx.collector.ser ...

  5. HDU2639Bone Collector II[01背包第k优值]

    Bone Collector II Time Limit: 5000/2000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  6. HDOJ 4336 Card Collector

    容斥原理+状压 Card Collector Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/O ...

  7. HDU 2602 Bone Collector WA谁来帮忙找找错

    Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collec ...

  8. Bone Collector(01背包)

    题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/N 题目: Description Many year ...

  9. (三)CMS Collector

    有些资料中,为区别parallel collector ,将应用与gc并发成为并行,在接下来的文章中,仍称为并发. -XX:useConcMarkSweepGC,可以用于minor gc和major ...

  10. zabbix登陆问题:cannot allocate shared memory for collector

    问题说明:在一台zabbix被监控服务器上(64位centos6.8系统,64G内容)启动zabbix_agent,发现进程无法启动,10050端口没有起来! 启动zabbix_agent进程没有报错 ...

随机推荐

  1. JS Unicode转中文,中文转Unicode,ASCII转Unicode,Unicode转ASCII

    在线转换工具https://oktools.net/unicode Unicode转中文 function decodeUnicode(str) { return unescape(str.repla ...

  2. 初探css-18 尺寸

    CSS 尺寸 (Dimension) CSS 尺寸 (Dimension) 属性允许你控制元素的高度和宽度.同样,它允许你增加行间距. 更多实例 这个例子演示了如何设置不同元素的高度. <sty ...

  3. Vue示例教程

    <!DOCTYPE html> <html lang="en" xmlns:v-bind="http://www.w3.org/1999/xhtml&q ...

  4. ip - Linux IPv4 协议实现

    SYNOPSIS(总览) #include <sys/socket.h> #include <net/netinet.h> tcp_socket = socket(PF_INE ...

  5. shared_ptr的原理与应用

    new与赋值的坑 赋值(assignment)和new运算符在C++与Java(或C#)中的行为有本质的区别.在Java中,new是对象的构造,而赋值运算是引用的传递:而在C++中,赋值运算符意味着& ...

  6. ZROI 19.08.05模拟赛

    传送门 写在前面:为了保护正睿题目版权,这里不放题面,只写题解. A \(21pts:\) 随便枚举,随便爆搜就好了. \(65pts:\) 比较显然的dp,设\(f_{i,j,k}\)表示在子树\( ...

  7. 提高Linux操作系统性能

    提高Linux操作系统性能 2011-01-05 13:48 佚名 字号:T | T 本文从磁盘,文件及文件系统,内存和编译等方面详细的讲述了如何对Linux系统性能进行调谐.不管是Linux服务器还 ...

  8. 【10】Python urllib、编码解码、requests、多线程、多进程、unittest初探、__file__、jsonpath

    1 urllib urllib是一个标准模块,直接import就可以使用 1.1get请求 from urllib.request import urlopen url='http://www.nnz ...

  9. Delphi---ShellExecute跨进程调用exe

    测试环境:Delphi7 + Win7 发起端 unit uRequest; interface uses Windows, Messages, SysUtils, Variants, Classes ...

  10. spark2.1.0 自定义AccumulatorV2累加少值(线程不安全)?

    一.踩坑经历 自定义的accumulator是线程不安全的,会造成累加结果不正确.自定找了很久没想到是线程不安全行成的. 二.解决方法 创建一个线程安全的集合变量(我用的是Java的Concurren ...