1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
mihalych1998 [28]
2 years ago
12

Write a method called findNames that meets the following specs: It takes two arguments: a list of strings, allNames, and a strin

g, wanted Creates and returns a new list containing only the strings from, allNames, that contain the name stored in wanted as a substring. List allNames should remain unmodified: do not delete, or modify the names in it. This should work in a case insensitive manner, but the names in your result list should be exactly as they are in A (i.e. not converted to lower case). We referred to allames and what the method retums as 'lists', but you are free to represent cach one of them however you want: array or ArrayList. No error checking needed. Example behavior: if allNames is: ["Bob Smith", "Elroy Jetson", "Christina Johnson", "Rachael Baker", "Chris Conly"] and wanted is "cHRis" the resulting list, should be: ["christina Johnson", "Chris Conly"] because only those two strings contain "chris"
Computers and Technology
1 answer:
Anna11 [10]2 years ago
8 0

Answer:

public class Solution {

   public static void main(String args[]) {

       String[] allNames = new String[]{"Bob Smith", "Elroy Jetson", "Christina Johnson", "Rachael Baker", "cHRis", "Chris Conly"};

       String searchString = "cHRis";

       

       findNames(allNames, searchString);

   }

   

   public static void findNames(String[] listOfName, String nameToFind){

       ArrayList<String> resultName = new ArrayList<String>();

       

       for(String name : listOfName){

           if (name.toLowerCase().contains(nameToFind.toLowerCase())){

               resultName.add(name);

           }

       }

       

       for(String result : resultName){

           System.out.println(result);

       }

   }

}

Explanation:

The class was created called Solution. The second line define the main function. Inside the main function; we initialized and assign an array called allNames to hold the list of all name. Then a String called searchString was also defined. The searchString is the string to search for in each element of allNames array. The two variables (allNames and searchString) are passed as argument to the findNames method when it is called.

The method findNames is defined and it accept two parameters, an array containing list of names and the name to search for.

Inside the findNames method, we initialized and assigned an ArrayList called resultName. The resultName variable is to hold list of element found that contain the searchString.

The first for-loop goes through the elements in the allNames array and compare it with the searchString. If any element is found containing the searchString; it is added to the resultName variable.

The second for-loop goes through the elements of the resultName array and output it. The output is empty if no element was found added to the resultName variable.

During comparison, the both string were converted to lower case before the comparison because same lowercase character does not equal same uppercase character. For instance 'A' is not same as 'a'.

You might be interested in
Sites like Zillow get input about house prices from a database and provide nice summaries for readers. Write a program where the
SCORPION-xisa [38]

a aj ji hfjizbhig jiad jv hD jug vhi SDhvb hbnsdubghi

a biabihb hsjgbidbihdgbhibsrhkgbhibshibvghibsdgjo

asbihdg hibsihbghibdshibghbshbg9bhisdbghivbhbhir

aa sbuogjanjfjnbsujoenngobuewwwwwwwwwwwwwwwwwwwwwwww0o

8 0
2 years ago
Create a division formula.
baherus [9]

Answer:

=(A4+B4+C4+D4+E4)/5

Explanation:

If we want to have the average of the passengers, first we must sum all the revenue and then divide it with passenger quantity.

In this particular example, I made the formula with 5 passengers, I sum the 5 revenues and then I divide with 5 passengers if there are more passengers we must sum all of them, and divided all of them, for example:

=(A4+B4+C4+D4+E4+F4)/6

4 0
3 years ago
What do work places allow a company to do
anygoal [31]
D. They provide a platform for collaboration
8 0
3 years ago
Write a program named Deviations.java that creates an array with the deviations from average of another array. The main() method
Westkost [7]

Answer:

hello your question is incomplete attached is the complete question and solution

answer : The solution is attached below

Explanation:

Below is a program named Derivations.java that creates an array with the deviations from average of another array.

3 0
3 years ago
Bill, a project manager, wants to hire external resources. What step should Bill take before hiring external resources?
devlian [24]

Answer:

bhai sahab kya question hai mujhe samajh mein hi nahin per Sara sale Kya Re Tu Hi Sab Kuchh Nahin

8 0
2 years ago
Other questions:
  • True or false the primary advantage of the worksheet is the ability to solve numerical problems quickly and accurately
    11·1 answer
  • What aspect of the internet makes it fault-tolerant?
    6·1 answer
  • Write a statement that declares a prototype for a function powerTo, which has two parameters. The first is a double and the seco
    14·1 answer
  • What is the part of the browser window that displays the content of the web page such as pictures and text called?
    10·1 answer
  • Assume you previously entered these lines of code.
    14·2 answers
  • A benefit of flashcards is that they are
    7·2 answers
  • To display the Color gallery, with the graphic selected, click the Color button in the ____ group on the PICTURE TOOLS FORMAT ta
    14·1 answer
  • kieran wants to search a database quickly for information on the last time a patient came to his medical facility.The informatio
    14·2 answers
  • What is internet marketing??
    13·1 answer
  • How do you open an application on the macOS?
    11·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!