Publish Your Article Here

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 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));


package com.java2novice.lambda;

public class Employee {

        private String name;
        private String account;
        private Integer salary;

        public Employee(String name, String account, Integer salary) {
       = name;
                this.account = account;
                this.salary = salary;

        public String toString() {

                return "name: "+ +" | account: "+ this.account +" | salary: "+this.salary;

        public String getName() {
                return name;

        public void setName(String 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;

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
<< Previous Program | Next Program >>

Java 8 Streams Examples

  1. How Java 8 Streams work?
  2. Java 8 Streams parallelism introduction.
  3. Explain non-interference behavior of Java 8 Streams.
  4. Create Java 8 Stream using Stream.of() method example.
  5. Create Java 8 Stream using List example.
  6. Create Java 8 Stream using Stream.generate() method.
  7. Java 8 Stream.filter() example.
  8. Java 8 example.
  9. Java 8 Stream flatmap method example.
  10. Java 8 Stream peek method example.
  11. Java 8 Stream distinct method example.
  12. Java 8 Stream sorted method example.
  13. Java 8 Stream limit method example.
  14. Java 8 Stream forEach method example.
  15. Java 8 Stream toArray method example.
  16. Java 8 Stream reduce method example.
  17. Java 8 Stream collect method example.
  18. Java 8 Stream concat method example.
  19. Java 8 Stream anyMatch(), allMatch() and noneMatch() example.
  20. Java 8 Stream findFirst(), findAny() example.
  21. Primitive type Stream example.
Knowledge Centre
Domain Naming Service(DNS)
It is very difficult to remember a set of numbers (IP address) to connect to the Internet. The Domain Naming Service(DNS) is used to overcome this problem. It maps one particular IP address to a string of characters. For example, implies com is the domain name reserved for US commercial sites, java2novice is the name of the company and www is the name of the specific computer, which is java2novice's server.
Famous Quotations
It is amazing what you can accomplish if you do not care who gets the credit.
-- Harry Truman

About Author

I'm Nataraja Gootooru, programmer by profession and passionate about technologies. All examples given here are as simple as possible to help beginners. The source code is compiled and tested in my dev environment.

If you come across any mistakes or bugs, please email me to [email protected].

Most Visited Pages

Other Interesting Sites

Reference: Java™ Platform Standard Ed. 7 - API Specification | Java™ Platform Standard Ed. 8 - API Specification | Java is registered trademark of Oracle.
Privacy Policy | Copyright © 2024 by Nataraja Gootooru. All Rights Reserved.