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进程没有报错 ...
随机推荐
- 错误 “SCRIPT7002: XMLHttpRequest: 网络错误 0x2ef3, ie浏览器兼容问题
参考:https://www.telerik.com/blogs/help!-running-fiddler-fixes-my-app- https://www.cnblogs.com/OpenCod ...
- Ubuntu:MySQL与phpmyadmin安装、配置并使用。
0. 小建议 Ubuntu 16.04.因为MySQL对于Ubuntu 18.04不是很适配,会出现终端MySQL无法输入中文等问题.如果用Ubuntu 18.04,会需要多解决很多细节问题. 建议将 ...
- CodeReview的一些原则
架构/设计/常规角度: 单一职责原则 一个类只能干一个事情,一个方法最好也只干一件事情.一个类既干UI的事情,又干逻辑的事情,这个在低质量的代码里是很常见. 行为是否统一 缓存是否统一 错误处理是否统 ...
- 第一节,搭建openwrt开发环境
一,安装VMware虚拟机或者VirtualBox虚拟机 安装过程就不在此赘述了.附上百度搜索来的链接,供大家参考. https://baijiahao.baidu.com/s?id=16233731 ...
- squid之------安装与基本配置
1.rpm安装squid yum -y install squid 2.squid主要组成部分 服务名:squid 主程序:/usr/sbin/squid 配置目录:/etc/squid 主配置文件: ...
- 关于Python你不得不知道的Python语言特点
首先什么是语言?什么是编程? 准确来说是:定义计算机程序的语言,用来向计算机发送指令 个人理解: 语言:是一种交流的工具或者方式.比如我们的汉语普通话.各地的方言.外语中的英语.俄语.日语等.我们 ...
- 微信小程序左右联动菜单(即可左联动,也可右联动)
<!-- 搜索 --> <view class="search"> <input class="search-box" place ...
- java常用类与包装类--常用类字符串String类、StringBuffer类、Stringbuilder类
1.String类 1.1String类的概念和储存结构: (1)字符串是一个比较特殊的对象,可以使用new,也可以不使用new来创建字符串对象 String s1 = new String(&quo ...
- 【NOIP2016提高A组模拟9.15】Map
题目 分析 发现,当原图是一棵树的时候,那么新建一条边后,就会变成环套树, 而环内的所有点对都是安全点对,如果环中有k个点,答案就是\(k(k-1)\) 联想到,当把原图做一遍tarjan缩点,每个环 ...
- web上传文件夹
文件夹数据库处理逻辑 publicclass DbFolder { JSONObject root; public DbFolder() { this.root = new JSONObject(); ...