1. 符串自带方法
@Test
public void contextLoads() {
String str = "woshidage";
boolean isblank = str.isBlank();
boolean isempty = str.isEmpty();
String result1 = str.strip();
String result2 = str.stripTrailing();
String result3 = str.stripLeading();
String copyStr = str.repeat(2);
long lineCount = str.lines().count();
System.out.println(isblank);
System.out.println(isempty);
System.out.println(result1);
System.out.println(result2);
System.out.println(result3);
System.out.println(copyStr);
System.out.println(lineCount);
}
2. HttpClient加强方法
@Test
public void test2() throws IOException, InterruptedException {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(URI.create("")).build();
BodyHandler<String> handler = HttpResponse.BodyHandlers.ofString();
HttpResponse<String> response = client.send(request,handler);
String body = response.body();
System.out.println(body);
}
@Test
public void test3() throws IOException, InterruptedException, ExecutionException {
HttpClient client = HttpClient.newHttpClient();
HttpRequest request = HttpRequest.newBuilder(URI.create("")).build();
BodyHandler<String> handler = HttpResponse.BodyHandlers.ofString();
CompletableFuture<HttpResponse<String>> response = client.sendAsync(request,handler);
HttpResponse<String> result = response.get();
String body = result.body();
System.out.println(body);
}