Skip to content

aqsbaticos/JC-Exploring-Java-String-Methods

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

9 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Laboratory: Exploring Java String Methods

Developed by: Baticos, Andric Quinn S.

Screenshot of Proof


Exercise 1: length() - Finding the String's Size

Code Snippet

Screenshot Proof

Prediction: This code will output 14 as there are 14 characters in the string "Hello, Cadets!" (including whitespace and symbols).

Output

Screenshot Proof

Observation: As expected, the value returned by the length() method was 14.


Exercise 2: charAt() - Accessing a Character

Code Snippet

Screenshot Proof

Prediction: This code will output the character 'l'.

Output

Screenshot Proof

Observation: As expected, the value returned by the charAt() method was 'l'.


Exercise 3: substring() - Extracting a Part of a String

Code Snippet

Screenshot Proof

Prediction: This code will output the string 'is ' (including the whitespace).

Output

Screenshot Proof

Observation: The value returned by the substring() method was 'is' only.


Exercise 4: toUpperCase() and toLowerCase() - Changing Case

Code Snippet

Screenshot Proof

Prediction: This code will output the strings "THIS IS A TEST" and "this is a test" respectively.

Output

Screenshot Proof

Observation: As expected, the value returned by the toUpperCase() and toLowerCase() methods were "THIS IS A TEST" and "this is a test" respectively.


Exercise 5: indexOf() - Finding a Character or Substring

Code Snippet

Screenshot Proof

Prediction: This code will output the indexes 16, 37, and -1.

Output

Screenshot Proof

Observation: As expected, the value returned by indexOf() were 16 (first index 'f' when fox matches, 37 (match z), and -1 (no match).


Exercise 6: equals() vs. equalsIgnoreCase() - Comparing Strings

Code Snippet

Screenshot Proof

Prediction: This code will output the values false, true, and true.

Output

Screenshot Proof

Observation: As expected, the values returned by equals() were false and true, and the value returned by equalsIgnoreCase() was true.


Exercise 7: replace() - Replacing Characters

Code Snippet

Screenshot Proof

Prediction: This code will output the new string "I like dogs. Cats are cute".

Output

Screenshot Proof

Observation: As expected, the string "cats" was replaced by "dogs".


Exercise 8: trim() - Removing Whitespace

Code Snippet

Screenshot Proof

Prediction: This code will remove the whitespace before and after 'Lots of spaces'. The length printed will be: 20 & 14.

Output

Screenshot Proof

Observation: As expected, the whitespaces were removed and reduced the length of the string.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages