Fahim Parkar Fahim Parkar - 1 year ago 117
Java Question

string size more than max limit of int

I have a huge set of strings, where I want to find the length of the each string and add them and display the total length of string.

To calculate the length, I use method as

, but I noticed that datatype of length() is int and max size of int is 2,147,483,647. However my string object have characters more then 2,147,483,647. Any suggestion how to get the length when it goes beyond int limit?

Answer Source

However my string object have characters more then 2,147,483,647

I doubt it: a String uses a char[] to store the characters and arrays can't hold more than Integer.MAX_VALUE elements. See also this post.

If you simply need to add the lengths of several strings, you can use a long variable instead.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download