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.
Java の String 配列は可変なのだろうか? 文字列が不変であることは知っていますが、文字列配列はどうですか?
文字列配列があり、内容を変更すると、新しい文字列オブジェクトが作成されますか? それとも、実際の値が変更されるだけですか?
前もって感謝します
配列では、各要素はオブジェクトへの単なるポインターです。だから、あなたが何かをするとき
String one = "1"; String two = "2"; String three = "3"; String four = "4"; String[] myStringArray = {one, two, three}; myStringArray[2] = four;
次に、配列の 3 番目の要素にあったポインターは、 threeではなくfourを指すようになりました。