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]
3 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]3 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
Write a loop that displays all possible combinations of two letters where the letters are 'a', or 'b', or 'c', or 'd', or 'e'. T
Dafna11 [192]

Answer:

for (char outerChar='a'; outerChar<='e'; outerChar++){

for (char innerChar='a'; innerChar<='e'; innerChar++){

cout << outerChar << innerChar << "\n";

}

}

3 0
3 years ago
Brainliest Answer!!
olganol [36]
The answer to your question is true
6 0
3 years ago
Read 2 more answers
Compare and contrast the various options that exist for acquiring software.
Softa [21]

Answer:

   The various options that exist for acquiring software are:

  •  By developing a various custom applications so that, they can satisfied the requirements in an organization.
  •  By purchasing various software application or packages for modify the software to meet the specific requirements.
  •  Used the open source software for developing the specific information system so that, the system are acquired.
  •  Developed the in-house capabilities and skills of employee, this is the main advantage for acquiring the software.  
6 0
3 years ago
According the text book the information system at first disseminate and then collect, store, process, and analyze the informatio
konstantin123 [22]

Answer:True

Explanation:

The above mentioned statement is correctly explaining the procedure of Information system

4 0
3 years ago
How does technology improve productivity at
Svetradugi [14.3K]

Answer:

Enables sending documents to multiple

recipients

Provides flexible work schedules and

environments

Explanation:

8 0
3 years ago
Read 2 more answers
Other questions:
  • How do forensic pathologist determine time of death
    13·1 answer
  • Most users find settings between ____ to be the most convenient option for how long the computer sits idle before the screen sav
    14·1 answer
  • Casey Griggs is a very capable computer engineer. Recently, he noticed a problem that computer engineers have, and thought of a
    13·1 answer
  • What type of identity theft occurs when a thief spends another person's money or opens a line of credit in their name?
    8·2 answers
  • Two technicians are discussing a resistance measurement. Technician A states that components being measured should be removed or
    10·1 answer
  • How do you reduce computer screen flicker
    11·1 answer
  • Problem 3. Consider the following recurrence, defined for n a power of 4 (for the time of some algorithm): T(n) = 3 if n = 1 2T(
    5·1 answer
  • What landforms are likely to form at this boundary
    15·1 answer
  • When would it be necessary to edit the information shown on an electronic business card?
    5·2 answers
  • If AL contains binary 1000 1111, which one will show the information of the binary bits in AL after performing operation SHR AL,
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!