2

Well, String is an often used type, working as an Object consumes more resource, why Sun designed it as an Object but not a simple variable like int

if someone says String can contain very long sentence, why it was not designed to be like int and Integer

Kitanski
  • 49
  • 3

2 Answers2

4

There are some advantage of being an Object instead of primitives

  1. No size limit
  2. you can implement utility methods for helping operations
  3. you can make it immutable
stinepike
  • 54,068
  • 14
  • 92
  • 112
0

If you want to be more efficient with storing text in memory you can keep it in a byte array.

Evgeniy Dorofeev
  • 133,369
  • 30
  • 199
  • 275