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 では、次の 2 つのコードに違いはありますか? メモリ使用量と文字列プールに関する回答を探しています。
最初:
String s = new String(); s = "abcdef";
二番目:
String s = new String("abcdef");
ありがとう。
最初の 1 つで、作成と値の割り当てを行います。2 つ目は、作成するだけです。最初のアクティビティで (ほぼ) 2 倍のプロセッサ アクティビティを作成します。メモリに関しては、違いはありません。
あなたの質問に対する文字列プールの説明:
Java 文字列プールとは何ですか? また、"s" は new String("s") とどう違うのですか?