Question
search method accepts ArrayList of Strings and a String called find and returns a String. It will look for an element within ArrayList that contains
search method accepts ArrayList of Strings and a String called find and returns a String.
It will look for an element within ArrayList that contains value of find
If it finds it, methods needs to return whole Element value.
If an instance of find doesn't exist return: "search failed"
for example:
search(["one apple","two orange","four banana"],"four")
returns:
"four banana"
("four banana" contains "four" so method returns "four banana")
search(["hello night","good world","java bye"],"goodbye")
returns:
"search failed"
(no "goodbye" in any element)
hint:
use contains string method to test if element has word value in it.
---------------------------
import java.util.ArrayList; import java.util.Scanner;
class Main {
//main method here public static void main(String[] args) {
Scanner scan = new Scanner(System.in);
ArrayList
//please add only 3 elements into your list
System.out.println("Enter the word you want to find from the list: "); }
public static String search(ArrayList
}
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started