0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

※備忘録 Java StringBuilderについて

Posted at

Stringの特徴

String s = "Hello";

不変(immutable)
一度作った文字列は 変更できない
文字を追加したり、置き換えたりすると 新しい String オブジェクトが作られる

String s = "Hello";
s = s + "World";

ここで s + " World" は 新しい String が作られる
元の "Hello" はそのまま残る
文字列を大量に操作すると メモリ効率が悪くなる

StringBuilderの特徴

StringBuilder sb = new StringBuilder("Hello");

可変(mutable)
文字列を変更しても 新しいオブジェクトは作られない
文字の追加、削除、反転などが効率よくできる

StringBuilder sb = new StringBuilder("Hello");
sb.append("World"); // 文字列を追加
sb.reverse(); // 文字列を逆順に
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?