Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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 string.length(), 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?

like image 561
Fahim Parkar Avatar asked Feb 18 '23 14:02

Fahim Parkar


1 Answers

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.

like image 192
assylias Avatar answered Feb 21 '23 03:02

assylias