XtraStudy Header

Blogs ➤ Articles

Java 8 Program to add prefix and suffix to the String using StringJoiner

Tags : #Java8, #Coding, #JavaProgram, #Java   Author : Admin
Updated : 14-Feb-2023 👁 133


Java 8 Program to add prefix and suffix to the String using StringJoinerJava 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);
   }
}


Output


String after adding # in suffix and prefix :
#Interview,Questions,Answers#

Comments
Comments (0)


App Link

xtrastudy android app
Others

Earn While You Learn
FAQ

Register Now

© 2022 Company, Inc. All rights reserved.