A community for students.

Here's the question you clicked on:

55 members online
  • 0 replying
  • 0 viewing


  • 3 years ago

how do i write a method that takes an integer and an integer array and returns a Boolean indicating whether the integer can be found in the array or not in java

  • This Question is Open
  1. anonymous
    • 3 years ago
    Best Response
    You've already chosen the best response.
    Medals 0

    If you can use an ArrayList instead, you can use the existing method 'contains'. If not, you could copy the implementation in java: public boolean contains(Object o) { return indexOf(o) >= 0; } where indexOf is: public int indexOf(Object o) { if (o == null) { for (int i = 0; i < size; i++) if (elementData[i]==null) return i; } else { for (int i = 0; i < size; i++) if (o.equals(elementData[i])) return i; } return -1; } If you know the list is sorted, you can use a binary search.

  2. Not the answer you are looking for?
    Search for more explanations.

    • Attachments:

Ask your own question

Sign Up
Find more explanations on OpenStudy
Privacy Policy

Your question is ready. Sign up for free to start getting answers.

spraguer (Moderator)
5 → View Detailed Profile

is replying to Can someone tell me what button the professor is hitting...


  • Teamwork 19 Teammate
  • Problem Solving 19 Hero
  • You have blocked this person.
  • ✔ You're a fan Checking fan status...

Thanks for being so helpful in mathematics. If you are getting quality help, make sure you spread the word about OpenStudy.

This is the testimonial you wrote.
You haven't written a testimonial for Owlfred.