| Author |
Just a simple for loop question
|
Lek Kin Wong
Ranch Hand
Joined: Feb 23, 2010
Posts: 30
|
|
why the second one work rather than the first one?
tomcat give me java.lang.ArrayIndexOutOfBoundsException: 2
|
 |
Han Jie
Greenhorn
Joined: Sep 24, 2010
Posts: 24
|
|
Hi Lek
Why would like you using filearray.length instead of filearray.length-1 with the second one?
|
 |
Abimaran Kugathasan
Ranch Hand
Joined: Nov 04, 2009
Posts: 2066
|
|
|
Arrays are zero based. And array length isn't equal to the last index of the array!
|
|BSc in Electronic Eng| |SCJP 6.0 91%| |SCWCD 5 92%|
|
 |
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56529
|
|
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.
|
[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
|
 |
Lek Kin Wong
Ranch Hand
Joined: Feb 23, 2010
Posts: 30
|
|
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?
|
 |
Wouter Oet
Saloon Keeper
Joined: Oct 25, 2008
Posts: 2700
|
|
|
You can use the Arrays class optionally with a Comparator. There is even a Oracle tutorial about it (here).
|
"Any fool can write code that a computer can understand. Good programmers write code that humans can understand." --- Martin Fowler
Please correct my English.
|
 |
Lek Kin Wong
Ranch Hand
Joined: Feb 23, 2010
Posts: 30
|
|
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.
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32830
|
|
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.
|
 |
 |
|
|
subject: Just a simple for loop question
|
|
|