• 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
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
Sheriffs:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
Saloon Keepers:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
Bartenders:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

lastIndexOf() Question

 
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If i have an array of integers called, say, integerArray[], and i am looking for the last location that contains, say, 1, then how do i use the lastIndexOf() method, as it does not seem to work when i try it.

my code is similar to:



Thanks
[ November 13, 2005: Message edited by: Sam Bluesman ]
 
Sheriff
Posts: 21865
105
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arrays don't have methods and have only 1 field, length.
java.util.Arrays has some utility methods for arrays, but no lastIndexOf, so you'll have to write your own utility class that implements it. Just traverse the array backwards, starting at intArray.length - 1.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or use the ArrayUtils class from http://jakarta.apache.org/commons/lang/
 
author and iconoclast
Posts: 24203
43
Mac OS X Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by Rob Spoor:
Arrays don't have methods



Actually they have all the methods of the class java.lang.Object: equals(), hashCode(), wait(), notify(), notifyAll(), toString(), finalize(), getClass(), and clone() (which is public in all array classes.)
 
Rob Spoor
Sheriff
Posts: 21865
105
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right, stupid of me. Since arrays are Objects of course they have these...
 
Marshal
Posts: 68061
258
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is lastIndexOf() in the ArrayList class, maybe?
 
Rob Spoor
Sheriff
Posts: 21865
105
Eclipse IDE Spring VI Editor Chrome Java Ubuntu Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In all Lists.
 
This cake looks terrible, but it tastes great! Now take a bite out of this tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!