capypad
0 day streak
java / beginner
Snippet

String Length and Concatenation

Strings in Java are objects representing sequences of characters. You can use the length() method to find the size and the '+' operator to join strings together.

snippet.java
java
1
2
3
String text = "Java";
int length = text.length();
String greeting = "Hello " + text + "!";
Breakdown
1
String text = "Java";
Creates a String object with the value 'Java'.
2
int length = text.length();
Calls a method to count the number of characters in the string.
3
String greeting = "Hello " + text + "!";
Concatenates three parts into a single new string.