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
Zigmanuir [339]
3 years ago
10

Create an ArrayList of strings to store the names of celebrities and athletes. Add 5 names to the list. Process the list with a

for loop and the get() method to display the names, one name per line. Pass the list to a void method. Inside the method, insert another name at Index 2 and remove the name at index 4. Use a Foreach loop to display the arraylist again, all names on one line separated by asterisks. After the method call in main, create an iterator for the arraylist and use it to display the list one more time.

Computers and Technology
1 answer:
mr Goodwill [35]3 years ago
7 0

Answer:

// ArrayList class is imported

import java.util.ArrayList;

// Iterator class is imported

import java.util.Iterator;

// Main class is defined

class Main {

   // main method to begin program execution

   public static void main(String args[]) {

       // names ArrayList of String is defined

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

       // 5 names are added to the list

       names.add("John");

       names.add("Jonny");

       names.add("James");

       names.add("Joe");

       names.add("Jolly");

       // for loop to print the names inside the arraylist

       for(int index = 0; index <names.size(); index++){

         System.out.println(names.get(index));

       }

       

       // A blank line is printed

       System.out.println();

       // A newMethod is called with names as argument

       newMethod(names);

       // A blank line is printed

       System.out.println();

       // Instance of Iterator class is created on names

       Iterator<String> iter

           = names.iterator();

 

       // Displaying the names after iterating

       // through the list

       while (iter.hasNext()) {

           System.out.println(iter.next());

       }

   }

   // the newmethod is created here

   public static void newMethod(ArrayList<String> inputArray){

     // A new name is added at index 2

     inputArray.add(2, "Smith");

     // the name in index 4 is removed

     inputArray.remove(4);

     // for each is used to loop the list and print

     for (String name : inputArray) {

       System.out.println(name);

       }

   }

}

Explanation:

The code is well commented. An output image is attached.

You might be interested in
er reports that he is having problems with his monitor. He explains that his laptop's liquid crystal display (LCD) is no longer
kati45 [8]

Answer:

diffuser

Explanation:

Based on the scenario being described, the most likely cause of the problem is a bad diffuser. This is a component found in nearly every type of LCD backlit displays and are used to produce an even array of lighting across the entire display. If this component fails then it will cause bright spots and dim spots throughout the display, similar to what the client is reporting in this scenario since the light is not being evenly distributed.

4 0
2 years ago
Describe the functions of a system software​
wel

Answer:

System Software is a set of programs that control and manage the operations of computer hardware. It also helps application programs to execute correctly. System Software are designed to control the operation and extend the processing functionalities of a computer system

8 0
2 years ago
Read 2 more answers
Which command button contains the following sub options as given in the picture?
DiKsa [7]

Answer:

D) Slide options

Explanation:

hope this helps

7 0
3 years ago
Read 2 more answers
The command to delete all the files that have filenames that starts with letter c or c and ends with a letter z or z is
dimaraw [331]
The command is : <span>rm [Aa]*[Zz] </span>
4 0
3 years ago
How do you use a iPad when it has a password ?
BaLLatris [955]
Take it to the Apple Store and they will help you or you can go on their site and press "Forgot Apple ID." If you choose the second option you have to enter the first and last name, and the email you used for the iCloud on the iPad. 
6 0
3 years ago
Read 2 more answers
Other questions:
  • What might be the best response to a cyberbuly attack
    6·2 answers
  • Which button could Pamela press in the Microsoft Word spell checker to make the word “colour” instantly change to “color” whenev
    11·1 answer
  • Is instant messaging a form of synchronous communication
    10·1 answer
  • Which of these is a method of selecting multiple items in Impress or PowerPoint? A. holding down the Ctrl key while clicking ite
    9·2 answers
  • In which of the following situations will a macro make your work more efficient?
    9·1 answer
  • Write a program that receives an character and displays its Unicode. Here is a sample run: Enter an character: E The Unicode for
    8·1 answer
  • How do you copy and paste plz let me know
    14·2 answers
  • What command is most effective at identifying different types of files?
    6·1 answer
  • Create a class to represent light bulbs
    7·1 answer
  • Where are 'if' and 'else' statements shown when printing a document in a word processor?
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!