0
0
Javaprogramming~15 mins

String comparison in Java - Interactive Code Practice

Choose your learning style8 modes available
ads_clickPractice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to compare two strings for equality.

Java
String a = "hello";
String b = "hello";
boolean result = a.[1](b);
🎯 Drag options to blanks, or click blank then click option
AequalsIgnoreCase
B==
CcompareTo
Dequals
Attempts:
3 left
2fill in blank
medium

Complete the code to compare two strings ignoring case differences.

Java
String a = "Hello";
String b = "hello";
boolean result = a.[1](b);
🎯 Drag options to blanks, or click blank then click option
AcompareTo
Bequals
CequalsIgnoreCase
DstartsWith
Attempts:
3 left
3fill in blank
hard

Fix the error in the code to correctly compare two strings.

Java
String a = "test";
String b = new String("test");
if (a.[1](b)) {
    System.out.println("Equal");
} else {
    System.out.println("Not equal");
}
🎯 Drag options to blanks, or click blank then click option
A==
Bequals
C!=
DcompareTo
Attempts:
3 left
4fill in blank
hard

Fill both blanks to create a map of strings to their lengths, but only include strings longer than 3 characters.

Java
Map<String, Integer> lengths = words.stream()
    .filter(word -> word.[1]() > 3)
    .collect(Collectors.toMap(word -> word, word -> word.[2]()));
🎯 Drag options to blanks, or click blank then click option
Alength
Blength()
Dsize()
Attempts:
3 left
5fill in blank
hard

Fill all three blanks to create a map of uppercase strings to their lengths, including only strings longer than 4 characters.

Java
Map<String, Integer> result = words.stream()
    .filter(word -> word.[1]() > 4)
    .collect(Collectors.toMap(word -> word.[2](), word -> word.[3]()));
🎯 Drag options to blanks, or click blank then click option
Alength()
BtoUpperCase()
DtoLowerCase()
Attempts:
3 left