新特性
public class Jdk11Demo {
public static void main(String[] args) {
autoTypeJudge();
StrongString();
http();
}
/**
* 网络请求
*/
private static void http() {
var request = HttpRequest.newBuilder()
.uri(URI.create("http://wanandroid.com/wxarticle/chapters/json"))
.GET()
.build();
var client = HttpClient.newHttpClient();
// 同步
HttpResponse<String> response = null;
try {
response = client.send(request, HttpResponse.BodyHandlers.ofString());
System.out.println(response.body());
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
// 异步
client.sendAsync(request, HttpResponse.BodyHandlers.ofString())
.thenApply(HttpResponse::body)
.thenAccept(System.out::println);
}
/**
* 字符串加强
*/
private static void StrongString() {
System.out.println(" ".isBlank());
System.out.println("标准的字符串");
System.out.println(" 首尾空格 ".strip());
System.out.println(" 头部空格".stripTrailing());
System.out.println("尾部空格 ".stripLeading());
System.out.println("Java11 ".repeat(3));
System.out.println("a\nb\nc\n".lines().count());
}
/**
* 动态类型推导判断
*/
private static void autoTypeJudge() {
var jdk11String = "hell jdk 11";
System.out.println(jdk11String);
var jdk11Int = 123;
System.out.println(jdk11Int);
}
}
结果
hell jdk 11
123
true
标准的字符串
首尾空格
头部空格
尾部空格
Java11 Java11 Java11
3
{"data":[{"children":[],"courseId":13,"id":408,"name":"鸿洋","order":190000,"parentChapterId":407,"userControlSetTop":false,"visible":1},{"children":[],"courseId":13,"id":409,"name":"郭霖","order":190001,"parentChapterId":407,"userControlSetTop":false,"visible":1},{"children":[],"courseId":13,"id":410,"name":"玉刚说","order":190002,"parentChapterId":407,"userControlSetTop":false,"visible":1},{"children":[],"courseId":13,"id":411,"name":"承香墨影","order":190003,"parentChapterId":407,"userControlSetTop":false,"visible":1},{"children":[],"courseId":13,"id":413,"name":"Android群英传","order":190004,"parentChapterId":407,"userControlSetTop":false,"visible":1},{"children":[],"courseId":13,"id":414,"name":"code小生","order":190005,"parentChapterId":407,"userControlSetTop":false,"visible":1},{"children":[],"courseId":13,"id":415,"name":"谷歌开发者","order":190006,"parentChapterId":407,"userControlSetTop":false,"visible":1},{"children":[],"courseId":13,"id":416,"name":"奇卓社","order":190007,"parentChapterId":407,"userControlSetTop":false,"visible":1},{"children":[],"courseId":13,"id":417,"name":"美团技术团队","order":190008,"parentChapterId":407,"userControlSetTop":false,"visible":1},{"children":[],"courseId":13,"id":420,"name":"GcsSloop","order":190009,"parentChapterId":407,"userControlSetTop":false,"visible":1},{"children":[],"courseId":13,"id":421,"name":"互联网侦察","order":190010,"parentChapterId":407,"userControlSetTop":false,"visible":1}],"errorCode":0,"errorMsg":""}