Flash cards
Review the key moves
1/4
Core idea
What is the main idea behind Java String toString() Method?
Lesson checks
Practice each idea before moving on
Short Mimo-style checks built from this lesson's code, terms, and sequence.
1Quick choice
Which statement best captures the main point of this lesson?
2Fill blank
Complete the missing token from the example code.
___ myStr = "Hello, World!";3Order
Put the learning moves in the order that makes the concept easiest to apply.
The toString() method returns the string itself.
Definition and Usage
Java String toString() Method
❮ String Methods
Example
String myStr = "Hello, World!";
System.out.println(myStr.toString());Definition and Usage
The toString() method returns the string itself.
This method may seem redundant, but its purpose is to allow code that is treating the string as a more generalized object to know its string value without casting it to String type.
Syntax
public String toString()Technical Details
| Returns: | The String object itself. |
|---|---|
| Java version: | Any |