LearnFrenzy
Sign in Take a free test

Strings and StringBuilder · Predict the Output · Question 17

String.join and repeat Answer, explanation & discussion

  • Output
  • Easy
  • 0 comments
  • Answer explained
  • Moderated community
Question 17 Back to Exercise

What is the output of the following Java program?

Main.java
import java.util.List;

public class Main {
    public static void main(String[] args) {
        List<String> langs = List.of("C", "C++", "Java");
        System.out.println(String.join(" | ", langs));
        System.out.println("=".repeat(5) + String.join("", "a", "b", "c").toUpperCase() + "=".repeat(5));
        System.out.println(String.join(",", List.of()).isEmpty());
    }
}
  • A C | C++ | Java =====ABC===== true Correct
  • B C|C++|Java =====abc===== true
  • C C | C++ | Java | =====ABC===== false
  • D [C, C++, Java] =====ABC===== true
Correct Answer: Option A

join puts the separator only between elements; joining an empty list gives an empty string.

Discussion & Comments 0

Share your method, a shortcut, or ask about a step you didn't follow.

No comments yet. Be the first to share your solution!

Post your comment

Comments appear after a quick review by our team.

Search LearnFrenzy

Esc

Quick links