• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Just a simple for loop question  RSS feed

 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
why the second one work rather than the first one?
tomcat give me java.lang.ArrayIndexOutOfBoundsException: 2

 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Lek

Why would like you using filearray.length instead of filearray.length-1 with the second one?
 
Ranch Hand
Posts: 2066
Clojure IntelliJ IDE Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arrays are zero based. And array length isn't equal to the last index of the array!
 
Marshal
Posts: 67164
169
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Lek Kin Wong
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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?
 
Bartender
Posts: 2700
IntelliJ IDE Opera
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can use the Arrays class optionally with a Comparator. There is even a Oracle tutorial about it (here).
 
Lek Kin Wong
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
Marshal
Posts: 61774
193
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!