1

When we declare a variable with data type String in Java, how many characters can we store in that variable?

For example, we write in code like:

String name;

This name variable is a string. So how many characters can we store in the variable name?

ApproachingDarknessFish
  • 14,133
  • 7
  • 40
  • 79
DhananjayK
  • 23
  • 5

2 Answers2

1

A little logic.

Java's string length returns int, so Integer max value might be the max size.

Suresh Atta
  • 120,458
  • 37
  • 198
  • 307
0

the boundary is 2^31-1 characters, since the getLength()-method of String returns an int-value. The other boundary is your RAM. So your String is limited by the boundary that is reached first

Sajad Karuthedath
  • 14,987
  • 4
  • 32
  • 49