Question

Write an implementation of the following Java method: /* search(ArrayList, int key) -> int method is...

Write an implementation of the following Java method:

/*

search(ArrayList, int key) -> int method is passed an array list of integers and an integer key method searches for the key in the array list and returns: the index of the key if it is in the array list -1 otherwise

*/

0 0
Add a comment Improve this question Transcribed image text
Answer #1

public static int search(ArrayList<Integer> al, int key)
{
for (int i=0; i<al.size(); i++)
{
if(al.get(i)==key)
return i;
}
return -1;
}

Add a comment
Know the answer?
Add Answer to:
Write an implementation of the following Java method: /* search(ArrayList, int key) -> int method is...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT