Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
文字列があり、String x = "oncetherewasaboy"; に置き換えたいと"there"し""ます。私は試しx.replace("there","");ましたが、これはそれを削除しません。これは最良の例ではありませんが、文字列の配列に対してこれを行っており、各インデックス内の情報の一部を"". ありがとう!
String x = "oncetherewasaboy";
"there"
""
x.replace("there","");
String は不変の Type です。不変オブジェクトとは、作成後に状態を変更できないオブジェクトです。したがって、文字列 x を変更することはできません。
文字列を変更することはできないため、replace メソッドは新しい変更を加えた新しい文字列を返します。したがって、 jlordo がすでに示唆しているように、次のように使用する必要があります
x = x.replace("there", "");