0
0
Javaprogramming~15 mins

String immutability 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 create a new string by adding " World" to the original string.

Java
String greeting = "Hello";
String newGreeting = greeting[1]" World";
🎯 Drag options to blanks, or click blank then click option
A+
B-
C*
D/
Attempts:
3 left
2fill in blank
medium

Complete the code to convert the string to uppercase.

Java
String text = "hello";
String upperText = text.[1]();
🎯 Drag options to blanks, or click blank then click option
AtoUpperCase
BtoLowerCase
Ctrim
Dsubstring
Attempts:
3 left
3fill in blank
hard

Fix the error in the code to correctly replace "cat" with "dog" in the string.

Java
String animal = "cat";
String newAnimal = animal.[1]("cat", "dog");
🎯 Drag options to blanks, or click blank then click option
AreplaceAll
BreplaceWith
CreplaceFirst
Dreplace
Attempts:
3 left
4fill in blank
hard

Fill both blanks to create a new string with "Java" repeated 3 times.

Java
String repeated = "Java".[1](3);
String result = repeated.[2]();
🎯 Drag options to blanks, or click blank then click option
Arepeat
BtoString
Ctrim
Dconcat
Attempts:
3 left
5fill in blank
hard

Fill all three blanks to create a new string with the first 4 characters of "immutable" in uppercase.

Java
String word = "immutable";
String part = word.[1](0, [2]);
String result = part.[3]();
🎯 Drag options to blanks, or click blank then click option
Asubstring
B4
CtoUpperCase
Dlength
Attempts:
3 left