[Logo]
Forums Register Login
Just a simple for loop question
why the second one work rather than the first one?
tomcat give me java.lang.ArrayIndexOutOfBoundsException: 2

Hi Lek

Why would like you using filearray.length instead of filearray.length-1 with the second one?
Arrays are zero based. And array length isn't equal to the last index of the array!
Please take the time to choose an appropriate forum for your posts. This forum is for questions on Servlets. For more information, please click this link ⇒ CarefullyChooseOneForum.

This post has been moved to a more appropriate forum.
 

Abimaran Kugathasan wrote:Arrays are zero based. And array length isn't equal to the last index of the array!


many thanksss!
so how do I sort array values in descending order?
You can use the Arrays class optionally with a Comparator. There is even a Oracle tutorial about it (here).
 

Wouter Oet wrote:You can use the Arrays class optionally with a Comparator. There is even a Oracle tutorial about it (here).



I just solve the problem with Arrays class, Thank.
 

Lek Kin Wong wrote: . . . I just solve the problem with Arrays class, Thank. . . .

Well done. Please give us a bit more detail about what you did, in case anybody else has the same problem later.
The harder I work, the luckier I get. -Sam Goldwyn So tiny. - this ad:
Rocket Oven Kickstarter - from the trailboss
https://coderanch.com/t/695773/Rocket-Oven-Kickstarter-trailboss


This thread has been viewed 788 times.

All times above are in ranch (not your local) time.
The current ranch time is
Jul 17, 2018 05:53:20.