ArrayList Sorting Enhanced For Loop Collections Class Auto-boxing Programming Assignment Label all program output so that it is clear what is happening! Please don't make me guess. Do some research on...

1 answer below »


  • ArrayList

  • Sorting

  • Enhanced For Loop

  • Collections Class

  • Auto-boxing





Programming Assignment


Label all program output so that it is clear what is happening! Please don't make me guess.



  1. Do some research on "auto-boxing." What is auto-boxing, and why it is useful? Give an example of a use case. Write a few lines of code that auto-box anintinto anInteger, and un-box anIntegerto anint.

  2. Declare anArrayListof Strings. Add 5 names to the collection. Output the Strings onto the console using anenhanced for loop.

  3. Take a few minutes to examine theJava Collections API(Links to an external site.).Shuffleyour list using a method from the API. Output the shuffled List.Sortthe list, and output the sorted list. Note thatCollections(with an s) is aclass, whileCollectionis aninterface. What does this difference mean to you?

  4. Search for a name that can be found in your list. In which location was it found? Search for a name that is not in the list. What location is reported?

  5. Describe why anequalsmethod and acompareTomethod are required to achieve searching and sorting of the elements of a list. What is the difference, and how might you use each?

  6. Convert your ArrayList to anarrayusingtoArray(). Output the elements of the array. Convert the array back into a list usingasList(). Output the elements of the ArrayList.



Please submit



  1. Your answers to the questions (in a text document, or in comments in your code - either is fine).

  2. Your source code (.java files(s)).

  3. Screenshots showing your program(s) running.

Answered Same DayMar 31, 2021

Answer To: ArrayList Sorting Enhanced For Loop Collections Class Auto-boxing Programming Assignment Label all...

Pulkit answered on Apr 01 2021
144 Votes
java/.idea/.gitignore
# Default ignored files
/shelf/
/workspace.xml
java/.idea/misc.xml




java/.idea/modules.xml






ja
va/.idea/workspace.xml






















1617299348432


1617299348432



java/Desktop.iml









java/Q1.class
public synchronized class Q1 {
public void Q1();
public static void main(String[]);
}
java/Q1.java
java/Q1.java
public class Q1 {

    public static void main(String[] args)
    {
    // creating an object of Integer class with a value
    Integer integer1 = new Integer(15);

    // unboxing the object
    int integer2 = integer1;

    // displaying both the values
    System.out.println("Auto-boxing value: " + integer1);
    System.out.println("Unboxing value: " + integer2);
    }
    }


java/Q1.PNG
java/Q2.class
public synchronized class Q2 {
public void Q2();
public static void main(String[]);
}
java/Q2.java
java/Q2.java
import java.util.ArrayList;
public class Q2 {

public static void main(String[] args)
{
ArrayList listStrings = new ArrayList<>();
listStrings.add("John");
listStrings.add("Susan");
listStrings.add("Alice");
listStrings.add("Mary");
listStrings.add("Ralph");

System.out.println("Displaying list contents using enhanced for loop: ");
for(String str : listStrings)
{
System.out.println(str);
}
}
}

java/Q2.PNG
java/Q3.class
public synchronized class Q3 {
public void Q3();
public static void...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here