Last Updated: January 3, 2026
32 quizzes
Join two strings representing a first and last name with a space between them.
String fullName = firstName.(" " + lastName);Click an option to fill the blank:
Check if an email string contains the '@' character to validate basic structure.
boolean valid = email.("@");Click an option to fill the blank:
Remove leading and trailing spaces from a user input string before processing.
String cleaned = input.();Click an option to fill the blank:
Which statement correctly creates a String from a literal using the string pool?
What does message.charAt(0) return when message is "Java"?
Which String method can be used to extract "World" from "Hello World"?
Why are Java Strings immutable?
Which class is best when building a long log message in a single-threaded method?
Which feature distinguishes StringBuffer from StringBuilder?
Which call correctly formats a price with two decimal places?
Which comparison correctly checks if two String variables have the same text?
You need to validate that an input string contains only digits. Which regex is most appropriate?
What is the result of this code? String s1 = "Java"; String s2 = "Java"; System.out.println(s1 == s2);
Which method is best to ignore letter case when checking a username?
Which StringBuilder method removes all characters it currently holds?
Order the steps to use a regex to find all numbers in a text with Pattern and Matcher.
Drag and drop to reorder, or use the arrows.
Order the steps to efficiently build a large CSV line using StringBuilder.
Drag and drop to reorder, or use the arrows.
What is the output of this code involving substring and length?
1String msg = "Hello, World!";
2String part = msg.substring(7, 12);
3System.out.println(part + " (" + part.length() + ")");What does this code print about string references and content?
1String a = "test";
2String b = new String("test");
3System.out.println(a.equals(b) + ":" + (a == b));What is the output when using StringBuilder with chained appends?
1StringBuilder sb = new StringBuilder("Java");
2sb.append(" ").append("Strings");
3System.out.println(sb.toString());Predict the output when formatting a double value for display.
1double value = 12.3456;
2String formatted = String.format("Result: %.2f", value);
3System.out.println(formatted);What single line does this regex code print?
1import java.util.regex.*;
2
3public class Main {
4 public static void main(String[] args) {
5 String text = "Order #12345 shipped";
6 Pattern p = Pattern.compile("#(\\d+)");
7 Matcher m = p.matcher(text);
8 String result = m.find() ? m.group(1) : "none";
9 System.out.println(result);
10 }
11}Find the bug in this code that is meant to compare two strings ignoring case.
Click on the line(s) that contain the bug.
public class CompareNames { public static boolean sameUser(String a, String b) { if (a.toLowerCase() == b.toLowerCase()) { return true; } return false; }}Find the bug in this code that is meant to build a log message using StringBuilder.
Click on the line(s) that contain the bug.
public class Logger { public static String buildLog(String level, String message) { StringBuilder sb = new StringBuilder(); sb.append("["); sb.append(level); sb.append("] "); sb.concat(message); return sb.toString(); }}Match each string-related class with its main characteristic.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Match each regex construct with what it matches.
Click an item on the left, then click its match on the right. Click a matched item to unmatch.
Complete the code to build and print an email address using StringBuilder.
String username = "user";String domain = "example.com";StringBuilder sb = new StringBuilder();sb.(username).("@").(domain);System.out.println(sb.toString());Click an option to fill blank 1:
Complete the code to validate that a phone string matches a simple digit-only pattern.
import java.util.regex.*;public class PhoneValidator { public static boolean isValid(String phone) { Pattern pattern = Pattern.("$"); Matcher matcher = pattern.matcher(phone); return matcher.(); }}Click an option to fill blank 1:
Complete the code to format a user's name and age into a single line.
String name = "Alice";int age = 30;String result = String.("Name: %s, Age: %d", , );System.out.println(result);Click an option to fill blank 1:
Complete the code to safely compare two Strings for equality, handling possible null values.
String a = getFirst();String b = getSecond();boolean same = != null && .();System.out.println("Same: " + same);Click an option to fill blank 1:
Click the line that will throw a StringIndexOutOfBoundsException at runtime.
Click on the line to select.
String text = "Hi";char ch = text.charAt(2);System.out.println(ch);Click the line that incorrectly compares two String values using == instead of equals.
Click on the line to select.
String status1 = new String("OK");String status2 = new String("OK");if (status1 == status2) { System.out.println("Same status");}