This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import org.springframework.boot.SpringApplication; | |
import org.springframework.boot.autoconfigure.SpringBootApplication; | |
import org.springframework.boot.web.support.SpringBootServletInitializer; | |
@SpringBootApplication | |
public class DemoApplication extends SpringBootServletInitializer{ | |
public static void main(String[] args) { | |
SpringApplication.run(DemoApplication.class, args); | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
- hosts: localhost | |
tasks: | |
- name: Server group | |
jcli_servergroup: | |
jboss_home: /Users/it-ops/Documents/java_dev/server/wildfly-10.0.0.Final/ | |
server_group_name: group1 | |
state: present | |
register: hasil |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | |
<modelVersion>4.0.0</modelVersion> | |
<groupId>com.rurocker.example</groupId> | |
<artifactId>demo</artifactId> | |
<version>0.0.1-SNAPSHOT</version> | |
<packaging>war</packaging> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Stream from Collection | |
List<String> list = new ArrayList<>(); | |
list.add("s1"); | |
list.add("s2"); | |
list.add("s3"); | |
list.stream() | |
.map( s -> "From collection " + s) | |
.forEach(System.out::println); | |
//Stream from Arrays class |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
list.stream() | |
.filter(i -> i % 2 == 0) | |
.map(i -> i * i) | |
.sorted() | |
.distinct() | |
.forEach(System.out::println); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Random random = new Random(); | |
List<Integer> list = new ArrayList<>(); | |
//create a list of random integers using stream. | |
//Don't have to be like this, just to show off | |
//because we are talking about stream | |
List<Integer> list = IntStream.range(0, 20) | |
.map(i -> random.nextInt(100)) | |
.boxed() //turns IntStream into Stream<Integer> | |
.collect(Collectors.toList()); //will be discussed in advance stream usage |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Car car1 = new Car("BMW","Red", 35000d); | |
Car car2 = new Car("BMW","Green", 35500d); | |
Car car3 = new Car("Ford","Yellow", 25000d); | |
Car car4 = new Car("Toyota","Red", 10000d); | |
//populate car model list whose have red values | |
List<String> redCars = Stream.of(car1, car2, car3, car4) | |
.filter(s -> s.getColor().equals("Red") ) //get all cars with red values | |
.map(c -> c.getModel()) //map to get the model only | |
.collect(Collectors.toList()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// list of negative number | |
List<Integer> negList = Arrays.asList(-4, -3, -2, -1); | |
// list of positive number | |
List<Integer> posList = Arrays.asList(1, 2, 3, 4); | |
// find the odd number in both lists with single stream operation | |
List<Integer> collector = Stream.of(negList, posList) | |
.flatMap(List::stream) //transform into stream of other objects | |
.filter(i -> i % 2 != 0) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//append all model into single line of string with default model: Renault | |
String carModels = cars.stream() | |
.map(c1 -> c1.getModel()) | |
.distinct() | |
.reduce("Renault", (s1, s2) -> s1 + "|" + s2); | |
System.out.println(carModels); | |
//Output: Renault|BMW|Ford|Toyota |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Car car1 = new Car("BMW", "Red", 35000d); | |
Car car2 = new Car("Ford", "Yellow", 25000d); | |
Car car3 = new Car("Toyota", "Red", 10000d); | |
Car car4 = new Car("BMW", "Green", 35500d); | |
List<Car> cars = Arrays.asList(car1, car2, car3, car4); | |
//append all model into single line of string | |
cars.stream() | |
.map(c1 -> c1.getModel()) |
OlderNewer