|
|
Java 8 Stream concat method example.
The Stream.concat() method creates a lazily concatenated stream whose elements are all the elements of the
first stream followed by all the elements of the second stream. The resulting stream is ordered if both of the input streams
are ordered, and parallel if either of the input streams is parallel. When the resulting stream is closed, the close handlers
for both input streams are invoked.
package com.java2novice.streams;
import java.util.ArrayList;
import java.util.List;
import java.util.stream.Stream;
import com.java2novice.lambda.Employee;
public class StreamConcatEx {
public static void main(String a[]) {
List<Employee> accEmpList = new ArrayList<>();
accEmpList.add(new Employee("Nataraja G", "Accounts", 8000));
accEmpList.add(new Employee("Nagesh Y", "Accounts", 15000));
List<Employee> adminEmpList = new ArrayList<>();
adminEmpList.add(new Employee("Vasu V", "Admin", 2500));
adminEmpList.add(new Employee("Amar", "Admin", 12500));
Stream.concat(accEmpList.stream(), adminEmpList.stream()).forEach(System.out::println);
}
}
|
package com.java2novice.lambda;
public class Employee {
private String name;
private String account;
private Integer salary;
public Employee(String name, String account, Integer salary) {
super();
this.name = name;
this.account = account;
this.salary = salary;
}
@Override
public String toString() {
return "name: "+ this.name +" | account: "+ this.account +" | salary: "+this.salary;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getAccount() {
return account;
}
public void setAccount(String account) {
this.account = account;
}
public Integer getSalary() {
return salary;
}
public void setSalary(Integer salary) {
this.salary = salary;
}
}
|
|
Output: |
name: Nataraja G | account: Accounts | salary: 8000
name: Nagesh Y | account: Accounts | salary: 15000
name: Vasu V | account: Admin | salary: 2500
name: Amar | account: Admin | salary: 12500
|
|
|
|
|
Java 8 Streams Examples
- How Java 8 Streams work?
- Java 8 Streams parallelism introduction.
- Explain non-interference behavior of Java 8 Streams.
- Create Java 8 Stream using Stream.of() method example.
- Create Java 8 Stream using List example.
- Create Java 8 Stream using Stream.generate() method.
- Java 8 Stream.filter() example.
- Java 8 Stream.map() example.
- Java 8 Stream flatmap method example.
- Java 8 Stream peek method example.
- Java 8 Stream distinct method example.
- Java 8 Stream sorted method example.
- Java 8 Stream limit method example.
- Java 8 Stream forEach method example.
- Java 8 Stream toArray method example.
- Java 8 Stream reduce method example.
- Java 8 Stream collect method example.
- Java 8 Stream concat method example.
- Java 8 Stream anyMatch(), allMatch() and noneMatch() example.
- Java 8 Stream findFirst(), findAny() example.
- Primitive type Stream example.
|
|
Procedural Vs Object-oriented Programs
In procedural program, programming logic follows certain procedures and the instructions are executed one after another.
In OOP program, unit of program is object, which is nothing but combination of data and code.
In procedural program, data
is exposed to the whole program whereas in OOPs program, it is accessible with in the object and which in turn assures the
security of the code.
Millions long for immortality who do not know what to do with themselves on a rainy Sunday afternoon.
-- Susan Erz
|