1.

What do you mean by StringJoiner?

Answer»

STRINGJOINER is a Java class that allows you to construct or create a SEQUENCE of strings (characters) that are separated by delimiters LIKE a hyphen(-), comma(,), etc. Optionally, you can also pass suffix and prefix to the char sequence.

Example: 

// importing StringJoiner class import java.util.StringJoiner; public class ExampleofStringJoiner{ public static void main(String[] args) { StringJoiner joinStrings = new StringJoiner(",", "[", "]"); // passing comma(,) and square-brackets as DELIMITER // Adding values to StringJoiner joinStrings.add("Scaler"); joinStrings.add("By"); joinStrings.add("InterviewBit"); System.out.println(joinStrings); } }

OUTPUT

[Scaler,By,InterviewBit]


Discussion

No Comment Found