A community for students.
Here's the question you clicked on:
 0 viewing
dhemmy
 2 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
dhemmy
 2 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

bdean20
 2 years ago
Best ResponseYou've already chosen the best response.0If 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.
Ask your own question
Sign UpFind more explanations on OpenStudy
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...
23
 Teamwork 19 Teammate
 Problem Solving 19 Hero
 Engagement 19 Mad Hatter
 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.