Home  >  Article  >  Java  >  How to use java to concatenate strings

How to use java to concatenate strings

PHPz
PHPzforward
2023-05-13 16:25:061609browse

1. The Java language allows the use of symbols to connect (splice) two strings.

2. When a string is concatenated with a non-empty string value, the latter will be converted into a string (any Java object can be converted into a string).

Example

int age = 13;
String rating = "PG" + age;  //将rating设置为 "PG13"
 
//使用静态的 join 方法可以把多个字符串放在一起
//并指定一个界定符分隔
String all = String.join("/","S","M","L","XL");  //all的值为 S/M/L/XL
 
//repeated的值为 javajavajava
String repeated = "java".repeat(3);

The above is the detailed content of How to use java to concatenate strings. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:yisu.com. If there is any infringement, please contact admin@php.cn delete