In Java 8 joining() method of Collectors Class is used to join various elements of a character or string array into a single string object.

package com.javatutsworld.stream;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.stream.Collectors;

public class Java8Join  {

    public static void main(String args[]) {

        List<AccountDetails> acctDetailsList = new ArrayList();
        acctDetailsList.add(new AccountDetails("Saaim", "00266767", 2000));
        acctDetailsList.add(new AccountDetails("Saaim", "00266767", 2000));
        acctDetailsList.add(new AccountDetails("Saaim", "00266767", 2000));
        acctDetailsList.add(new AccountDetails("Sudhir", "00266788", 30000));
        acctDetailsList.add(new AccountDetails("Gaurav", "00266798", 30000));
        acctDetailsList.add(new AccountDetails("Gaurav", "00266798", 90000));
        acctDetailsList.add(new AccountDetails("Ram", "00266799", 50000));
        acctDetailsList.add(new AccountDetails("Ram", "00266799", 50000));
        acctDetailsList.add(new AccountDetails("Ram", "00266799", 2000));

        String joinName = acctDetailsList.stream().map(x -> x.getName())
            .collect(Collectors.joining(", ", "[", "]"));
        System.out.println(joinName);

        String joinName1 = acctDetailsList.stream().map(x -> x.getName())
                .collect(Collectors.joining(" | ", "[", "]"));
        System.out.println(joinName1);
    }
}


package com.javatutsworld.stream;

public class AccountDetails {
    private String name;
    private String accountNumber;
    private Integer amount;

    public AccountDetails(String name, String accountNumber, Integer amount) {
        super();
        this.name = name;
        this.accountNumber = accountNumber;
        this.amount = amount;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getAccountNumber() {
        return accountNumber;
    }

    public void setAccountNumber(String accountNumber) {
        this.accountNumber = accountNumber;
    }

    public Integer getAmount() {
        return amount;
    }

    public void setAmount(Integer amount) {
        this.amount = amount;
    }
}

Output:

[Saaim, Saaim, Saaim, Sudhir, Gaurav, Gaurav, Ram, Ram, Ram]
[Saaim | Saaim | Saaim | Sudhir | Gaurav | Gaurav | Ram | Ram | Ram]