0
Why string of arrays in java read n-1 values??
For example: String a[]=new String[5]; for(i=0;i<a.length();i++) Read or print only four values why but its size is 5?? But in integer type it read and print 5 values as usual....
2 Answers
+ 5
Array indexing starts from 0.
So if there are 5 elements then the indexes are from 0 to 4. This means if your n=5 then the index will range from 0 to n-1.
arr.length -> returns length of the array
arr.length() -> returns length of the string
0
Avinesh tanq