Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

How would i finish this code? Make a copy of an ArrayList with an explicit loop.

ID: 3929297 • Letter: H

Question

How would i finish this code?

Make a copy of an ArrayList with an explicit loop. Complete the following code. Complete the following file: Array Lis tCopy. java import java.util.ArrayList; import java.util.Scanner; public class ArrayListCopy public static void main(String[] args) {Arraylist words = new ArrayList(); Scanner in = new Scanner(System.in); while (in.hasNextO) words.add(in.next()); ArrayList copyOfWords = new ArrayList();//Use a for loop to copy the contents of words ... words.remove(0);//Shouldn't affect the copy System.out.println(words); System.out.println(copyOfWords);

Explanation / Answer

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

for(String s:words)

{

copyOfWords.add(s);

}

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote