Java 8 Program to add prefix and suffix to the String using StringJoiner
Tags :
Author :
Updated :
👁 133
Java 8 Program to add prefix and suffix to the String using StringJoiner |
To write a program in java to add prefix and suffix in a given String we will use StringJoiner class, a newly added in Java 8.
In the below program We will be adding “#“ and “#” as a prefix and suffix in the string.
import java.util.StringJoiner;
public class Main {
public static void main(String[] args) {
StringJoiner stringJoiner = new StringJoiner(",", "#", "#");
stringJoiner.add("Interview");
stringJoiner.add("Questions");
stringJoiner.add("Answers");
System.out.println("String after adding # in suffix and prefix :");
System.out.println(stringJoiner);
}
}
String after adding # in suffix and prefix :
#Interview,Questions,Answers#