Show the output of the following code:
import java.uti1.* ;
public class Test {
public static void main(String[] args) {
List<String> list =
Arrays.asList(“yellow”, “red”, “green”, “blue”);
Collections.reverse(list);
System.out.println(list);
List<String> list1 =
Arrays.asList(“yellow”, “red”, “green”, “blue”);
List<String> list2 = Arrays.asList(“white”, “black”);
Collections.copy(list1, 1ist2);
System.out.println(list1);
Collection<String> c1 = Arrays.asList ( “red”, “cyan”);
Collection<String> c2 = Arrays.asList(“red”, “blue”);
Collection<String> c3 = Arrays.asList(“pink”, “tan”);
System.out.println(Collections.disjoint(c1, c2));
System.out.println(Collections.disjoint(c1, c3));
Collection<String> collection =
Arrays.asList(“red”, “cyan”, “red”);
System.out.println(Collections.frequency(collection, “red”));
}
}
Want to see the full answer?
Check out a sample textbook solutionChapter 20 Solutions
Introduction to Java Programming and Data Structures, Comprehensive Version (11th Edition)
Additional Engineering Textbook Solutions
Introduction To Programming Using Visual Basic (11th Edition)
Java How to Program, Early Objects (11th Edition) (Deitel: How to Program)
Java How To Program (Early Objects)
Database Concepts (8th Edition)
Software Engineering (10th Edition)
Starting Out with Java: From Control Structures through Data Structures (4th Edition) (What's New in Computer Science)
- Your activity: write a same java program that will accept 20 integer in a list and returns the index of the first occurrence of the smallest element in the array. Also, write a program to test your method. Write a Java method, smallestIndex, that takes as its parameters an int array and its size, and returns the index of the (first occurrence of the) smallest element in the array. public class Array_labExercise2 { public static void main(String[] args) { int[] list = {56, 34, 67, 54, 23, 87, 66, 92, 15, 32, 55, 15, 88, 22, 30}; System.out.print("List elements: "); printArray(list); System.out.println(); System.out.println("Index of the (first occurenc of the) " + "smallest element in list is: " + smallestIndex(list)); System.out.println("Smallest element in list is: " + list[smallestIndex(list)]); } public static void printArray(int[] list) { int counter; for (counter = 0; counter < list.length; counter++) System.out.print(list[counter] + " ");…arrow_forwardIn Java what is stored in the array list after the following Java code executes? list[0] = 5; for (int i = 1; i < 6; i++) { list[i] = i * i + 5; if ( i > 2) list[i] = 2 * list[i] – list[i– 1]; }arrow_forwardPlease write in JAVA, Im trying to get a program that Returns first index where given value is found in list (if exist). param value - value to be searched. return first index of the value or -1 if value does not exist public boolean set(int index, int value) throws IndexOutOfBoundsException { //Implement this method return false; }arrow_forward
- Please write in C++ Please write a program that uses a class named QuadProb that uses a hash table using quadratic probing that has a function for insertion, deletion, and search. Please do not use anything from the STL.arrow_forwardThis is needed in Java Given that an ArrayList of Strings named nameList has already been created and names have already been inserted, write the statement necessary to delete the name at index 15.arrow_forwardStringSorter.java is below: import java.io.*; // for Reader (and subclasses), Writer (and subclasses) and IOExceptionimport java.util.*; // for List, ArrayList, Iterator public class StringSorter { ArrayList lines; // given that we don't really know how to deal with a read/write error (IOException) // inside the functions, we'll let it pass through public void readFromStream(Reader r) throws IOException { BufferedReader br=new BufferedReader(r); lines=new ArrayList(); while(true) { String input=br.readLine(); if(input==null) break; lines.add(input); } } public void writeToStream(Writer w) throws IOException { PrintWriter pw=new PrintWriter(w); Iterator i=lines.iterator(); while(i.hasNext()) { pw.println((String)(i.next())); } } // returns the index of the largest element in the list static int findIdxBiggest(List l, int from, int to) { String…arrow_forward
- In java, Implement a method that removes all duplicates. Keep the first instance of the element but remove all subsequent duplicate elements.public void removeDuplicates() see the picture for the right output. Given files: Demo6.java public class Demo6 { public static void main(String[] args) { MyLinkedList<String> list = new MyLinkedList<>(); TestBench.addToList(list); TestBench.addToList(list); TestBench.addToList(list); TestBench.addToList(list); for (int x = 0; x < list.size(); x += 1 + x/3) { System.out.println("Removing element at index: " + x); list.remove(x); } System.out.println("Result"); System.out.println(list); System.out.println("Shuffling"); list.shuffle(7777); System.out.println(list); System.out.println("Removing duplicates (keeping first instance)"); list.removeDuplicates(); System.out.println(list); }} TestBench.java import java.util.AbstractList; public class TestBench { public static…arrow_forward2 Write a java program. call it sortWords. Read from the command line a list of words, any number, from 1 to as many as the user wants. Store the words (strings) in an arraylist. Sort the list in alphabetical order. Print the list with a comma and space between each word. Words should be output in the SAME case as the user gives them. For an A make the sort be case insensitive AND remove the , from after the last word. example: java sortWords book car tree apple house --> apple, book, car, house, tree (The already existing answer on Chegg failed the codePost tests)arrow_forwardWrite Java statements to add the integers 1001, 1100, and 1110 to the resulting ArrayList import java.util.*;public class test { public static void main(String[] args) { //Set n =25 int n = 25; //ArrayList of Integer type with size,n=25 ArrayList<Integer> list = new ArrayList<Integer>(n); for(int i = 0;i<n;i++){ //Assign -1 to all the objects of the array list,list list.add(-1); } //Add 1001 to the list list.add(1001); //Add 1100 to the list list.add(1100); //Add 1110 to the list list.add(1110); //Reset the number of elements in the list becomes 28 //Use size() method to get the size of the list. n=list.size(); //for loop to print the list for(int i = 0;i<n;i++){ System.out.print(list.get(i) + " "); } }} 1. Write the Java statement to display the size of the resulting ArrayList from above.arrow_forward
- (Intro to Python) Q6. Spot the error in the following code that is supposed to append x to the end of list and print it? How would you fix it? x = 2t = [6, 3, 9, 1]t = t.append(x) print(t, type(t))arrow_forwarddo the changes in this program according to the given instruction import java.util.*;class CourseManager{//toatl students each section can holdstatic int max_Students;//mapping of each sections w.r.t to courseHashMap<String,ArrayList<Section> > courses ; //constructor for CourseManagerpublic CourseManager(int max){max_Students = max;courses = new HashMap<>();}//class Person which will be used by teacher and students to inherit its propertiesstatic class Person{String name;int age;public Person(String name , int age ){this.name = name;this.age = age;}}//teacher classstatic class Teacher extends Person{int id;public Teacher(int id , String name , int age ){super(name , age );this.id = id;}}//student classstatic class Student extends Person{int id;public Student(int id , String name , int age ){super(name , age );this.id = id;}}//section classstatic class Section{int section;String course ;Teacher instructor;int size ;HashMap<Integer ,Student >…arrow_forwardConsider the interface below:import java.util.NoSuchElementException; public interface MyList<E> { public int getSize(); public void insert(E data) throws ListOverflowException; public E getElement(E data) throws NoSuchElementException; public boolean delete(E data); // returns false if the data is not deleted in the list public boolean search(E data); // returns index of data, else -1 is return}a. Use an array object to store the elements of the list object. The program should be able to show its size, get element, delete, and search from the array. b. This array object will have a fixed size of five (5) and that an attempt to insert an element into the array when full will result to a ListOverflowException.arrow_forward
- Database System ConceptsComputer ScienceISBN:9780078022159Author:Abraham Silberschatz Professor, Henry F. Korth, S. SudarshanPublisher:McGraw-Hill EducationStarting Out with Python (4th Edition)Computer ScienceISBN:9780134444321Author:Tony GaddisPublisher:PEARSONDigital Fundamentals (11th Edition)Computer ScienceISBN:9780132737968Author:Thomas L. FloydPublisher:PEARSON
- C How to Program (8th Edition)Computer ScienceISBN:9780133976892Author:Paul J. Deitel, Harvey DeitelPublisher:PEARSONDatabase Systems: Design, Implementation, & Manag...Computer ScienceISBN:9781337627900Author:Carlos Coronel, Steven MorrisPublisher:Cengage LearningProgrammable Logic ControllersComputer ScienceISBN:9780073373843Author:Frank D. PetruzellaPublisher:McGraw-Hill Education