-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFP15JavaMadeEasy.java
76 lines (58 loc) · 2.11 KB
/
FP15JavaMadeEasy.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
package com.ysingh.functional;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
public class FP15JavaMadeEasy {
public static void main(String[] args) throws IOException {
listOperations();
fileOperations();
threadOperations();
}
private static void listOperations() {
List<String> courses = Arrays.asList("Spring", "Spring Boot", "API", "Microservices", "AWS", "PCF", "Azure", "Docker", "Kubernetes");
List<String> modifyableCourses = new ArrayList<>(courses);
modifyableCourses.replaceAll(str -> str.toUpperCase());
System.out.println(modifyableCourses);
modifyableCourses.removeIf(course -> course.length() < 6);
System.out.println(modifyableCourses);
}
private static void fileOperations() throws IOException {
System.out.println("---------------------------------");
Files.lines(Paths.get("file.txt")).forEach(System.out::println);
System.out.println("---------------------------------");
Files.lines(Paths.get("file.txt")).map(str -> str.split(" ")).flatMap(Arrays::stream).distinct().sorted().forEach(System.out::println);
System.out.println("---------------------------------");
Files.list(Paths.get(".")).filter(Files::isDirectory).forEach(System.out::println);
System.out.println("---------------------------------");
}
private static void threadOperations() {
Runnable runnable = new Runnable() {
@Override
public void run() {
for(int i=0; i<10000; i++) {
System.out.println(Thread.currentThread().getId()+ ":" + i);
}
}
};
Thread thread1 = new Thread(runnable);
thread1.start();
Thread thread2 = new Thread(runnable);
thread2.start();
Thread thread3 = new Thread(runnable);
thread3.start();
Runnable runnable2 = () -> {
for(int i=0; i<10000; i++) {
System.out.println(Thread.currentThread().getId()+ ":" + i);
}
};
Thread thread4 = new Thread(runnable2);
thread4.start();
Thread thread5 = new Thread(runnable2);
thread5.start();
Thread thread6 = new Thread(runnable2);
thread6.start();
}
}