Question: Task 1 : Working with String Methods Create a new Java class called StringLab. Inside the main ( ) method, create a String variable with

Task 1: Working with String Methods
Create a new Java class called StringLab.
Inside the main() method, create a String variable with the value " Welcome to the Java String Lab! ".
Use the following methods on this string and print the results:
length(): Print the length of the string.
charAt(): Print the character at index 7.
substring(): Extract and print the word "Java" from the string.
toUpperCase() and toLowerCase(): Print both the uppercase and lowercase versions of the string.
indexOf(): Find and print the index of the first occurrence of "Java".
contains(): Check if the string contains the word "Lab" and print the result.
replace(): Replace "Java" with "Java Programming" in the string and print the result.
split(): Split the string by spaces and print each word.
trim(): Trim any leading or trailing spaces and print the result.
equals() and equalsIgnoreCase(): Compare the string "java string lab!" with " Welcome to the Java String Lab! " and print the results for both methods.
Task 2: Working with StringBuilder
Create a new StringBuilder object initialized with the value "StringBuilder Lab".
Perform the following operations:
append(): Append the text "- Learning Java" to the StringBuilder.
insert(): Insert the text " is fun" after the word "Lab".
delete(): Delete the word "Learning" from the StringBuilder.
reverse(): Reverse the entire string and print it.
Task 3: Working with StringBuffer
Create a new StringBuffer object initialized with the value "Multithreading Lab".
Perform the same operations as in Task 2(append(), insert(), delete(), reverse()).

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!