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

How to use java to concatenate strings

PHPz
Release: 2023-05-13 16:25:06
forward
1656 people have browsed it

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);
Copy after login

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!

Related labels:
source:yisu.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template