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]
4 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]4 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
JAVA
qwelly [4]

public class MyClass {

   public static void main(String args[]) {

     int x = 1;

     int total = 0;

     for (int i = 1; i <= 10; i++){

         x *= i;

         total += x;

     }

     System.out.println(total);

   }

}

This program finds the sum of that series to the tenth term, the sum is: 4037913. I hope this helps.

6 0
3 years ago
How do open online courses help with independent learning
Dahasolnce [82]

Answer:

One of the most powerful benefits of online courses is that they enable students to learn at the time, place, and pace that best suits their individual learning style. ... If there is a class discussion, you can take time to gather your thoughts rather than be in a race to get the teacher's attention.

Explanation:

6 0
3 years ago
Read 2 more answers
Debug the program so it prints the factorial of a positive integer entered by the user. This is calculated by multiplying all th
Monica [59]

Your main problem was declaring int prod in the while loop. This caused prod to be reset back to 1 every time the while loop ran.

3 0
3 years ago
After reviewing the various types of network connections available, a client chooses a network connection that is considered to
andriy [413]

Answer:

Wired Network Connection

Explanation:

The two major types of connection is <em>Wired</em> and <em>Wireless </em>connection. The wired connection helps to transfer data between two devices using <em>Ethernet network cable</em>. The wireless connection on the other hand transfer data between endpoints using <em>microwave signals or radio frequency</em>.

<em>Wired connection</em> is preferred over <em>Wireless</em> because of interference which could be caused by other networks as well as wall obstructing the connection.

7 0
4 years ago
Physical parts of components of a computer system is called
3241004551 [841]
The correct answer is tangible objects 
4 0
3 years ago
Other questions:
  • Following are groups of three​ phrases, which group states three ways to improve your​ concentration?
    13·1 answer
  • What are 3 things that can make cyberbullying especially harmful​
    12·1 answer
  • The disk drive is a secondary storage device that stores data by _____ encoding it onto a spinning circular disk.
    14·1 answer
  • Which of the following resources is an example of a web-based application?
    15·1 answer
  • When executing System.out.println(a2), the toString() method in the Object class is invoked. The program cannot be compiled, bec
    11·1 answer
  • Sensory cues are used for script writers to be able to get more creative with the story their are scripting for (i.e.
    15·1 answer
  • What is the main difference between weathering, erosion and leaching​
    9·1 answer
  • A file named "games.txt" exists and has 80 lines of data. You open the file with the following line of code.
    7·2 answers
  • Is computing gcse easy or hard
    10·2 answers
  • Select the correct answer.
    8·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!