Collector的使用
一、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的使用的更多相关文章
- 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 ...
- hdu 2602 Bone Collector(01背包)模板
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=2602 Bone Collector Time Limit: 2000/1000 MS (Java/Ot ...
- Jmeter plugin jp@gc - PerfMon Metrics Collector
Jmeter由于是开源工具,所以目前有很多插件可以供使用,最简单的方法是先把Plugin Manager安装了 下载地址:https://jmeter-plugins.org/wiki/Plugins ...
- 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 ...
- HDU2639Bone Collector II[01背包第k优值]
Bone Collector II Time Limit: 5000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- HDOJ 4336 Card Collector
容斥原理+状压 Card Collector Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- HDU 2602 Bone Collector WA谁来帮忙找找错
Problem Description Many years ago , in Teddy’s hometown there was a man who was called “Bone Collec ...
- Bone Collector(01背包)
题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=87125#problem/N 题目: Description Many year ...
- (三)CMS Collector
有些资料中,为区别parallel collector ,将应用与gc并发成为并行,在接下来的文章中,仍称为并发. -XX:useConcMarkSweepGC,可以用于minor gc和major ...
- zabbix登陆问题:cannot allocate shared memory for collector
问题说明:在一台zabbix被监控服务器上(64位centos6.8系统,64G内容)启动zabbix_agent,发现进程无法启动,10050端口没有起来! 启动zabbix_agent进程没有报错 ...
随机推荐
- mybatis返回map结果集
今天突发奇想,想用mybatis返回一个map结果集,结果我就整了一下午,不过终于解决了 1.如果你确定返回的数据只有一条,你可以这样整 xml中: <select id="searc ...
- iconv_open - 分配一个字符集转换的描述符
总览 (SYNOPSIS) #include <iconv.h> iconv_t iconv_open (const char* tocode, const char* fromcode) ...
- Java引用与C语言指针的区别
1.现象 指针在运行时可以改变其所指向的值(地址)即指向其它变量,而引用一旦和某个对象绑定后就不能再改变,总是指向最初的对象. 2.编译 程序在编译时分别将指针和引用添加到符号表上,符号表上记录的是变 ...
- (转) Oracle SQL优化必要的全表扫描思路分析
大多数情况下,我们需要避免SQL在查询时进行全表扫描(FTS),但是对于必须需要进行全表扫描的情况,也可以进行一些优化处理. 即使全表扫描是检索所需数据的唯一可行方法,仍然有多种方法来提升查询性能.优 ...
- Codeforces 987 K预处理BFS 3n,7n+1随机结论题/不动点逆序对 X&Y=0连边DFS求连通块数目
A /*Huyyt*/ #include<bits/stdc++.h> #define mem(a,b) memset(a,b,sizeof(a)) #define pb push_bac ...
- MyEclipse内存不足?这里有你想要的问题解决方案
[MyEclipse CI 2019.4.0安装包下载] No.1 打开MyEclipse目录下的myeclipse.ini文件 在后面修改下面几个属性: vmargs Xms512m ( Java能 ...
- Rsync以守护进程(socket)的方式传输数据
Rsync以守护进程(socket)的方式传输数据 Rsync服务部署 一.以守护进程(socket)的方式传输数据(重点) 部署环境: 分别用uname命令查看各系统相关信息 1 2 ...
- 签发的用户认证token超时刷新策略
https://segmentfault.com/a/1190000014545422
- 【Linux】环境搭建基础
1 部署环境基本过程 有部署文档的话,根据文档进行部署.一般情况下,部署过程如下 1.1第一次的时候 1.安装依赖软件 java(jdk.tomcat.redis.mysql) python py2 ...
- hibernate中save()、get()、load()、update()、saveorupdate()、merge()等方法
1.save()方法 直接传个user对象 session.save(user); 2.get()方法和load()方法 get(): 传id session.get(UserInfo. ...