String
public class Main {
public static void main(String[] args) {
String myString1 = "Welcome";
String myString2 = " to ";
String myString;
myString = myString1 + myString2;
System.out.println(myString);
int year = 2022;
myString = myString + year;
System.out.println(myString);
float price = 2.2f;
myString = myString + ' ' + price;
System.out.println(myString);
}
}
The snippet result is
Welcome to
Welcome to 2022
Welcome to 2022 2.2
The String type could combine nearly every type in Java and append values together. The expression looks like this:
String + String = String
String + Charater = String
String + Number = String
Last updated