0
0
Javaprogramming~15 mins

Common string methods in Java - Mini Project: Build & Apply

Choose your learning style8 modes available
folder_codeCommon string methods
📖 Scenario: You are working on a simple Java program that processes a user's full name to extract useful information.
🎯 Goal: Build a Java program that uses common string methods to analyze and manipulate a full name.
📋 What You'll Learn
Create a String variable with a full name
Create an int variable to store the length of the name
Use string methods to find the first name and last name
Print the length, first name, and last name
💡 Why This Matters
🌍 Real World
Processing user names is common in apps that register users or display profiles.
💼 Career
Knowing string methods helps in data cleaning, user input validation, and text processing tasks.
Progress0 / 4 steps
1
Create the full name variable
Create a String variable called fullName and set it to the exact value "John Doe".
Java
💡 Need a hint?

Use String fullName = "John Doe"; to create the variable.

2
Find the length of the full name
Add an int variable called nameLength that stores the length of fullName using the length() method.
Java
💡 Need a hint?

Use int nameLength = fullName.length(); to get the length.

3
Extract the first and last names
Create two String variables: firstName and lastName. Use indexOf(' '), substring() methods on fullName to get the first and last names.
Java
💡 Need a hint?

Use indexOf(' ') to find the space, then substring() to get parts.

4
Print the results
Use System.out.println to print nameLength, firstName, and lastName each on its own line.
Java
💡 Need a hint?

Use System.out.println(variable); to print each value.