public class StringReplace { public StringReplace() { // 文字列を格納するための変数を宣言する String stTarget = "ABCD"; // 文字列 "ABC" を "1234" に置き換える stTarget = stTarget.replace("ABC", "1234"); // 1 文字だけを置き換える場合は char 型を使用する stTarget = stTarget.replace('D', '5'); // 置換後の文字列を表示する System.out.println(stTarget); } public static void main(String[] args) { StringReplace stringReplace = new StringReplace(); } }