Question: Write a method that takes an ArrayList and an int value and returns the first index at which value appears in the ArrayList. If the

Write a method that takes an ArrayList and an int value and returns the first index at which value appears in the ArrayList.
If the value does not exist in the ArrayList, return -1
For example, if we had an ArrayList list with the values [10,20,30,20]:
search(list,20)
Should return
1
Because 20 first appears at index 1 in the ArrayList.
If we had an ArrayList list with the values [10,20,30,20]:
search(list,40)
Should return
-1
Because 40 does not appear in the ArrayList.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!