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....

19th Mar 2020, 12:00 PM
V Chandu
V Chandu - avatar
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
19th Mar 2020, 12:02 PM
Avinesh
Avinesh - avatar
0
Avinesh tanq
20th Mar 2020, 1:13 AM
V Chandu
V Chandu - avatar