Java - How to get the index of a given element in an array -


I have an array of such contacts:

  public class applications {private scanner input ; Personal contact [] contact; Private Ent Aranyam; Public application () {input = new scanner (System.in); Contact = new contact [5]; ArrayNum = 0; }  

And what I want to do is enter a person's name on the contact list, and if they are found in their list, they come back like an index:

  System.out.println ("Who do you want to remove?"); String name = input.nextLine (); (Contact C: contact) {if (c.getName (). Equals (name)} {// get index here}}  

I tried to research it, but No answers or guides seem very clear on this, so I hope someone can explain this to me.

Instead use a loop using a counter.

 for  (int i = 0; i & lt; contacts.length, i ++) {if (contact [i] .getName (). Equals (name)) {// Do something with the index, i}}  

Comments

Popular posts from this blog

Member with no value in F# -

java - Joda Time Interval Not returning what I expect -

c# - Showing a SelectedItem's Property -