Question

In: Computer Science

Java: Determine the ouotput of this code ArrayList<String>list=new ArrayList<String>();             list.add("Namath");           &

Java:

Determine the ouotput of this code

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

            list.add("Namath");

            list.add("Sauer");

            list.add("Maynard");

            list.add("Namath");

            list.add("Boozer");

            list.add("Snell");

            list.add("Namath");

            list.add("Atkinson");

            list.add("Lammonds");

            list.add("Dockery");

            list.add("Darnold");

            list.remove(2);

            list.set(2, "Brady");

            list.remove(2);

            list.set(4,"Unitas");

            list.add(1,"Lamomica");

            list.add(3,"Hanratty");

            list.remove("Namath");

            list.remove(list.size()-1);

            list.remove(2);

            list.set(7, "Riggins");

            Iterator iter = list.iterator();  

        while (iter.hasNext())

        {   System.out.print(iter.next() + " ");  

             

        }

             

      }

}

Solutions

Expert Solution

import java.util.ArrayList;
import java.util.Iterator;

//TestCode.java
public class TestCode {
    public static void main(String[] args) {
        ArrayList<String> list=new ArrayList<String>();

        list.add("Namath");

        list.add("Sauer");

        list.add("Maynard");

        list.add("Namath");

        list.add("Boozer");

        list.add("Snell");

        list.add("Namath");

        list.add("Atkinson");

        list.add("Lammonds");

        list.add("Dockery");

        list.add("Darnold");

        list.remove(2);

        list.set(2, "Brady");

        list.remove(2);

        list.set(4,"Unitas");

        list.add(1,"Lamomica");

        list.add(3,"Hanratty");

        list.remove("Namath");

        list.remove(list.size()-1);

        list.remove(2);

        list.set(7, "Riggins");

        Iterator iter = list.iterator();

        while (iter.hasNext())

        {   System.out.print(iter.next() + " ");
        
        }
    }

}

Lamomica Sauer Boozer Snell Unitas Atkinson Lammonds Riggins


Related Solutions

Determine the outputs of the code: String[]array= {"Namath","Sauer","Namath","Namath","Snell","Snell","Namath","Namath","Namath", "Maynard","Namath","Namath"};        ArrayList<String>list=new ArrayList<String>(); &nbs
Determine the outputs of the code: String[]array= {"Namath","Sauer","Namath","Namath","Snell","Snell","Namath","Namath","Namath", "Maynard","Namath","Namath"};        ArrayList<String>list=new ArrayList<String>();        for(int i=0;i<array.length;i++)        {            list.add(array[i]);        }        System.out.println("OUTPUT 1");        System.out.println(list);        System.out.println("OUTPUT 2");        for(int i=0;i<list.size();i++)        {            if(list.get(i).equals("Namath"))            {                System.out.println(i+"\t"+ list.remove(i));            }        }        System.out.println("OUTPUT 3");        for(String s:list)        {           ...
Move all zeros in an arraylist to the end of the list using a temp(java). if...
Move all zeros in an arraylist to the end of the list using a temp(java). if it is an array the code would look like the code below, change it to fit an arraylist int count = 0;     int temp;     for (int i = 0; i < n; i++) {     if ((arr[i] != 0)) {         temp = arr[count];         arr[count] = arr[i];         arr[i] = temp;         count = count + 1;     }     } }
3.1 Write code that creates an ArrayList object named list and fills list with these numbers...
3.1 Write code that creates an ArrayList object named list and fills list with these numbers (using one or a pair of for or while loops): 0 1 2 3 4 0 1 2 3 4 3.2 Consider the ArrayList object named list containing these Integers: list = { 1, 2, 3, 4, 5, 4, 3, 2, 1, 0 } What are the contents of list after this loop completes? for (int i = 1; i < 10; ++i) {...
Code in Java Write a recursive method, reverseString, that accepts a String and returns the String...
Code in Java Write a recursive method, reverseString, that accepts a String and returns the String reversed. Write a recursive method, reverseArrayList, that accepts an ArrayList of Strings and returns the ArrayList in reserve order in reserve order of the input ArrayList. Write a main method that asks the user for a series of Strings, until the user enters “Done” and puts them in an ArrayList. Main should make use to reverseArrayList and reverseString to reverse each String in the...
Given two ArrayLists of Strings (ArrayList<String>), write a Java method to return the higher count of...
Given two ArrayLists of Strings (ArrayList<String>), write a Java method to return the higher count of the characters in each ArrayList.  For example, if list1 has strings (“cat, “dog”, “boat”, “elephant”) and list 2 has strings (“bat”, “mat”, “port”, “stigma”), you will return the value 18.  The list 1 has 18 characters in total for all its strings combined and list2 has 16 characters for all of its strings combined.  The higher value is 18. If the character count is the same, you...
Java Programming CS 209 Data Structure 1. Create a method that takes an ArrayList of String...
Java Programming CS 209 Data Structure 1. Create a method that takes an ArrayList of String and returns a copy of that ArrayList with no duplicates. The relative ordering of elements in the new ArrayList should be the same. Sample Input: {"qwerty", "asdfgh", "qwer", "123", "qwerty", "123", "zxcvbn", "asdfgh"} Sample Output: {"qwerty", "asdfgh", "qwer", "123", "zxcvbn"}
UML Diagram for this java code //java code import java.util.*; class Message { private String sentence;...
UML Diagram for this java code //java code import java.util.*; class Message { private String sentence; Message() { sentence=""; } Message(String text) { setSentence(text); } void setSentence(String text) { sentence=text; } String getSentence() { return sentence; } int getVowels() { int count=0; for(int i=0;i<sentence.length();i++) { char ch=sentence.charAt(i); if(ch=='a' || ch=='e' || ch=='i' || ch=='o' || ch=='u' || ch=='A' || ch=='E' || ch=='I' || ch=='O' || ch=='U') { count=count+1; } } return count; } int getConsonants() { int count=0; for(int i=0;i<sentence.length();i++)...
since firstN is a string it can't compare to an ArrayList * list so how am i suppose to write these parts comparing the string to the list[mid]
c++ question:int ArrayList::binarySearchID(string firstN) const{   int first = 0;         int last = length - 1;         int mid = (first + last) / 2;   bool found = false;   int index;   while (!found && last >= first)   {       if (firstN == list[mid])       {           found = true;       }       else if (firstN > list[mid])       {           first = mid - 1;       }       else if (firstN < list[mid])       {           last...
Is List type is an interface in the Java collections framework? Classes Vector, ArrayList, and LinkedList...
Is List type is an interface in the Java collections framework? Classes Vector, ArrayList, and LinkedList are the same data structure but implement data storage in different ways. Classes, that implement Map interface in Java collections framework are used for storing what type of data? Declare and instantiate a list of elements of type String. Name this list myArray. what type of data structure is Stack? LinkedList data structure in Java collections is implemented as doubly linked lists. In PriorityQueue...
Write Java code that accepts the integer input (from keyboard) in an arraylist named num1 and...
Write Java code that accepts the integer input (from keyboard) in an arraylist named num1 and stores the even integers of num1 in another arraylist named evennum.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT