Win a copy of Practical SVG this week in the HTML/CSS/JavaScript forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

index of an element in an array

 
krishna prasad gunasekaran
Ranch Hand
Posts: 158
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
good day,
hw to find the index of an element in an array.
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
java.util.List has an indexOf method (providing your equals method is implemented correctly), and can convert from an Array to a List using java.util.Arrays.asList
 
Henry Wong
author
Sheriff
Posts: 22542
109
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, if the elements of the array are sorted, then you could use the java.util.Arrays class. Otherwise, I believe you have to loop through the array to find the element that you want.

Henry
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!