Question

Java Framework Collection Assign. Create a class called ArrayListExample Create a ArrayList object called languageList which...

Java Framework Collection Assign.

Create a class called ArrayListExample

Create a ArrayList object called languageList which accept type of String

Add English, French, Italian and Arabic strings into languageList array object

Print languageList using Iterator object

Sort ArrayList object alphabetically

Print languageList using Iterator object

Solution will produce following:

  1. ArrayListExample class
  2. ArrayList object called languageList
  3. ArrayListExampleTest class with main method
0 0
Add a comment Improve this question Transcribed image text
Answer #1

import java.util.ArrayList;
import java.util.Collections;
import java.util.Iterator;
//Create a class called ArrayListExample
public class ArrayListExample {
   public static void main(String[] args) {
//       Create a ArrayList object called languageList which accept type of String
       ArrayList<String> languageList = new ArrayList<String>();
//       Add English, French, Italian and Arabic strings into languageList array object
       languageList.add("English");
       languageList.add("French");
       languageList.add("Italian");
       languageList.add("Arabic");
      
       System.out.print("Before Sort\t:");
       // Looping ArrayList using Iterator
//       Print languageList using Iterator object
Iterator it = languageList.iterator();
while (it.hasNext())
System.out.print(it.next() + " ");
// Sort ArrayList object alphabetically
Collections.sort(languageList);
System.out.println();
System.out.print("After Sort\t:");
// Print languageList using Iterator object
// Looping ArrayList using Iterator
Iterator it2 = languageList.iterator();
while (it2.hasNext())
System.out.print(it2.next() + " ");
  
   }
}

Add a comment
Know the answer?
Add Answer to:
Java Framework Collection Assign. Create a class called ArrayListExample Create a ArrayList object called languageList which...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Design a JAVA class called Course. The class should contain: ○ The data fields courseName (String),...

    Design a JAVA class called Course. The class should contain: ○ The data fields courseName (String), numberOfStudents (int) and courseLecturer (String). ○ A constructor that constructs a Course object with the specified courseName, numberOfStudents and courseLecturer. ○ The relevant get and set methods for the data fields. ○ A toString() method that formats that returns a string that represents a course object in the following format: (courseName, courseLecturer, numberOfStudents) ● Create a new ArrayList called courses1, add 5 courses to...

  • I've been assigned to create a new Java application called "CheckString" (without the quotation marks) according...

    I've been assigned to create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines. ** Each method below, including main, should handle (catch) any Exceptions that are thrown. ** ** If an Exception is thrown and caught, print the Exception's message to the command line. ** Write a complete Java method called checkWord that takes a String parameter called word, returns nothing, and is declared to throw an Exception of type Exception. In the...

  • create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines....

    create a new Java application called "CheckString" (without the quotation marks) according to the following guidelines. ** Each method below, including main, should handle (catch) any Exceptions that are thrown. ** ** If an Exception is thrown and caught, print the Exception's message to the command line. ** Write a complete Java method called checkWord that takes a String parameter called word, returns nothing, and is declared to throw an Exception of type Exception. In the method, check if the...

  • Java Programming: Task: - Write some Java code that creates a collection (an ArrayList, a TreeSet...

    Java Programming: Task: - Write some Java code that creates a collection (an ArrayList, a TreeSet or a LinkedList), puts some elements into it, creates an iterator, uses it a bit and then (1) changes the collection using one of the four techniques listed (not using the first iterator) and then (2) calls one of the three iterator methods listed. (See instructions below for details) - After writing the code answer the following questions: 1.) What is the result? 2.)...

  • About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which...

    About Classes and OOP in C++ Part 1 Task 1: Create a class called Person, which has private data members for name, age, gender, and height. You MUST use this pointer when any of the member functions are using the member variables. Implement a constructor that initializes the strings with an empty string, characters with a null character and the numbers with zero. Create getters and setters for each member variable. Ensure that you identify correctly which member functions should...

  • Create a Java program that will store 10 student objects in an ArrayList, ArrayList<Student>. A student object con...

    Create a Java program that will store 10 student objects in an ArrayList, ArrayList<Student>. A student object consists of the following fields: int rollno String name String address Implement two comparator classes to sort student objects by name and by rollno (roll number). Implement your own selection sort method and place your code in a separate Java source file. Do not use a sort method from the Java collections library.

  • Write a simple Java program with the following naming structure: Open Eclipse Create a workspace called...

    Write a simple Java program with the following naming structure: Open Eclipse Create a workspace called hw1 Create a project called hw1 (make sure you select the “Use project folder as root for sources and class files”) Create a class called Hw1 in the hw1 package (make sure you check the box that auto creates the main method). Add a comment to the main that includes your name Write code that demonstrates the use of each of the following basic...

  • Create a nested inner class inside a file called LinkedList.java called the ListIterator. ListIterator: This public...

    Create a nested inner class inside a file called LinkedList.java called the ListIterator. ListIterator: This public class is nested within an LinkedList data structure and allows us to traverse the elements in any collection, access any data element and remove any data elements of the collection. It also adds the functionality to move forward and backward, which is new functionality. We are going to build this data structure from scratch. Instance variables (fields) are: mPrevious (Node) – the previous node...

  • This is Java 0) Create a project called Lab2-Areas 1) Create a java class called Areas...

    This is Java 0) Create a project called Lab2-Areas 1) Create a java class called Areas (do not include the main method in this class) 2) Create a method for the following: - areaCircle - areaSquare - areaTriangle - areaRectangle - areaTrapezoid 3) Create another class called CalculateAreas 4) Have the main method in this class. Instantiate/Construct the Area object 5) Initialize variables for the appropriate sides (base, height, etc.) 6) Initialize variables for the 5 areas from the Area...

  • 3. Create a program named TestArrayList, and declare an ArrayList with an initial capacity of 10....

    3. Create a program named TestArrayList, and declare an ArrayList with an initial capacity of 10. Insert one copy of the string "Python", five copies of the string "Java" followed by four copies of the string "C++" so that your vector is now filled to сараcity. Add a class method named printArrayList to print out all the elements stored within an ArrayList on separate lines. Test your method to be sure it works a) Add a class method named delete...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT