• Post Reply Bookmark Topic Watch Topic
  • New Topic

"exists" method for arrays?  RSS feed

 
Vince Aggrippino
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is there something similar to an exists or defined method for arrays that will not generate java.lang.ArrayIndexOutOfBoundsException?

Here are some non-working examples of what I want to do:


So, I know several ways that don't work. Is there a way to do this in Java?

Thank you,
Vince
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why don't you just check the length of the array ?
(myArray.length)
 
Kino Lobo
Greenhorn
Posts: 20
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Take a look at the ArrayListclass...
you may find something interesting there...
 
Vince Aggrippino
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're right. For what I want, all I need to do is use myArray.length. I'm very new to Java. I'm a Perl guy, originally, I I guess I'm having trouble getting out of that mindset.

Thanks also to Kino. The ArrayList class does do some neat things. It's more robust than I was looking for, but it gives me ideas

-- Vince
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm a Perl guy

Nobody is perfect Have fun with Java.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!