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
A student is helping a friend with a home computer that can no longer access the Internet. Upon investigation, the student disco
Firlakuza [10]

Answer:

Option (D) is the right answer.

Explanation:

DHCP term used as a short form of dynamic host configuration protocol, which is used to assigns the IP address automatically according to the network.

According to the scenario, the system is getting the wrong IP address that resulting in internet disconnection which is a failure of the DHCP server because it is responsible for assigning the right IP address to the system.

Hence option (D) is the most appropriate answer.

While other options are wrong because of the following reasons:

  • Static IP is the type of IP address which is fix and doesn't change in the system after rebooting, hence it has no connection in the change of IP address.
  • If the DHCP server is working well there is no chance of interference from the surrounding device.
  • Network setting has no connection with computer power supply as SMPS is used to give power and boot system only.
8 0
4 years ago
Over the years, workplace discrimination has become________.
natta225 [31]

Over the years, workplace discrimination has become more subtle.

5 0
3 years ago
A wireless network was recently installed in a coffee shop and customer mobile devices are not receiving network configuration i
siniylev [52]

Answer:

make sure the DHCP server is functional

Explanation:

5 0
4 years ago
A business-to-consumer (B2C) website tracks the items you place in a shopping cart using _____. Group of answer choices the Tran
steposvetlana [31]

Answer:

The answer is "cookies".

Explanation:

The B2C websites refer to companies, that directly sell services and products without the need for a distributor. It refers to the online merchants, which provide the offer on the products and services via the internet to customers.  It uses the cookie in a small amount of data within the browser memory for the process and once you visit those websites on the internet, OS transfer cookies for your internet browser. It includes an ID as well as its URL, and the incorrect choice can be defined as follows:

  • The TLS protocol is the wrong choice because it is used in the privacy and data security.
  • The crawlers are also a wrong choice because it is used in automatically searches.
  • An electronic wallet is used to store your money, that's why it is wrong.
7 0
4 years ago
Print media experienced a revival in 1981 as a result of what device?
baherus [9]

Answer:

c) Personal computer

Explanation:

8 0
4 years ago
Other questions:
  • To remove any hidden days from your document before sharing it, what should you do?
    7·1 answer
  • Most smartphones use operating systems developed by ________.
    10·1 answer
  • A résumé can be delivered through _____.a.
    9·2 answers
  • Read the following scenario and decide who, if anyone, is committing sexual harassment:
    13·2 answers
  • One of the files you should now have in your fileAsst directory is TweedleDee/hatter.txt. Suppose that you wished to copy that f
    5·1 answer
  • What is the term for water wave that is created by an underwater earthquake
    5·1 answer
  • When was kale discovered?
    9·1 answer
  • Menus are attached to the windows by calling
    15·1 answer
  • Cheri's teacher asked her to write a program using the input() function. What will this allow her program to do?
    8·2 answers
  • Importance of software in computer​
    14·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!