Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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 arr = new ArrayList(); System.out.println("Enter words for the list : ");

//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 r, String find) { //Implement your method here

}

}

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Valuation, Measuring And Managing The Value Of Companies

Authors: Tim Koller, Marc Goedhart, David Wessels

7th Edition

1119611865, 9781119611868

More Books

Students also viewed these Finance questions

Question

1. Create a brief vision statement for your venture.

Answered: 1 week ago