提交 8ade246f 编写于 作者: C chenjianqiang

jdk learn

上级 47c52fdd
......@@ -3,7 +3,7 @@
<component name="ProjectKey">
<option name="state" value="project://e2804f05-5315-4fc6-a121-c522a6c26470" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="17" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>
\ No newline at end of file
package com.newJDK.jdk10;
import java.util.List;
/**
* 10 var 学习
* @author lx
* @date 2021/11/30 16:41
* https://mp.weixin.qq.com/s/6yBUSfDCP_cqJAm0uRBFvQ
**/
public class VarLearn {
public static void main(String[] args) {
}
public static void var(){
var a = "555";
System.err.println(a.getClass().getTypeName());
}
}
package com.newJDK.jdk9;
import java.util.Optional;
/**
* 9 对于 Optional 的学习
*
* @author lx
* @date 2021/11/30 14:31
**/
public class OptionalLearn {
public static void main(String[] args) {
System.out.println(ProcessHandle.current().pid());
System.out.println(ProcessHandle.current().info());
}
public static void isEmptyIsPresent() {
// Optional.ofNullable(null); == Optional.empty();
Optional<Object> empty = Optional.empty();
// 非空 = true 空 = false
System.out.println(empty.isPresent());
// 空 = true
System.out.println(empty.isEmpty());
Optional<String> s = Optional.ofNullable("5");
System.out.println(s.isPresent());
System.out.println(s.isEmpty());
}
public static void ifPresentOrElse() {
Optional<String> s = Optional.ofNullable(null);
//空 就不执行
s.ifPresent(System.out::println);
//空不空在方法内区分
s.ifPresentOrElse(
y -> System.out.println("不是空的" + y),
() -> System.out.println("空的")
);
}
public static void or() {
Optional<Object> s = Optional.ofNullable("4444");
// s空的 就返回else里面的,s非空就返回s的值
Object s1 = s.orElse("6");
System.err.println(s1);
// s空的 就验证or是不是空的, s非空就返回
Optional<Object> or = s.or(() -> Optional.ofNullable("5555"));
System.err.println(or.get());
}
}
package com.newJDK.jdk9;
import java.util.List;
import java.util.stream.Stream;
/**
* 9 对于 stream 流的学习
* @author lx
* @date 2021/11/30 14:31
**/
public class StreamLearn {
public static void takeWhile(){
// 依次寻找直至不符合条件,找到一个向下传递一个
List<Integer> integerList = List.of(11, 33, 66, 8, 9, 13);
integerList.stream().takeWhile(x -> x < 50).forEach(System.out::println);
}
public static void dropWhile(){
// 依次寻找直至不符合条件,找打一个删除一个,剩下的向下传递
List<Integer> integerList = List.of(11, 33, 66, 8, 9, 13);
integerList.stream().takeWhile(x -> x < 50).forEach(System.out::println);
}
public static void iterate(){
// 使用原始 iterate() 方法输出数字 1~10
Stream.iterate(1, i -> i + 1).limit(10).forEach(System.out::println);
// 使用新的 iterate() 重载方法输出数字 1~10
Stream.iterate(1, i -> i <= 10, i -> i + 1).forEach(System.out::println);
}
}
......@@ -3,11 +3,21 @@ package com.pattern;
import com.pattern.BuilderPattern.materials.BuilderMain;
import com.pattern.CompositePattern.materials.CompositeMain;
import java.io.Serializable;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
/**
* @author lx
*/
public class PatternApplication {
/**
* 请确保您的JDK版本是最新版本哦 jdk.17
*
* @param args main
*/
public static void main(String[] args) {
/*
......@@ -106,11 +116,24 @@ public class PatternApplication {
*/
new CompositeMain().main();
/*
12.组合模式
new CompositeMain().main();
2021-11-25:一个实体包含了小规模业务
*/
List<String> list = List.of("x", "www", "yy", "zz");
Map<Integer, List<String>> result = list.stream()
.collect(Collectors.groupingBy(
String::length,
Collectors.filtering(
s -> s.contains("z"),
Collectors.toList())
)
);
System.err.println(result.toString());
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册