どうも、ちょげ(@chogetarou)です。
文字列(string)の先頭に文字列を追加する方法を紹介します。
方法

文字列(string)の先頭に文字列を追加するには、「+」演算子を使います。
具体的には、「+」演算子の左辺に先頭に追加する文字列、右辺に追加先の文字列を指定します。
//text1の先頭にtext2を追加
String result = text2 + text1;
上記の「+」演算子は、右辺の文字列の先頭に左辺の文字列を追加します。
使用例
public class Main {
public static void main(String[] args) throws Exception {
String text = "World";
String result = "Hello," + text;
System.out.println(text);
System.out.println(result);
}
}
出力:
World
Hello,World
コメント