package com.javacodegeeks.corejava.util;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
public class MyCollectionsExample {
public static void main(String[] args) {
List<Double> temperatureList = new ArrayList<Double>();
temperatureList.add(33.9);
temperatureList.add(37.8);
temperatureList.add(40.5);
temperatureList.add(15.3);
temperatureList.add(25.6);
// Print elements of temperatureList
System.out.println(temperatureList);
//Get maximum temperature from temperatureList
Double max = Collections.max(temperatureList);
System.out.println("Maximun temperature: "+max);
//Get minimum temperature from temperatureList
Double min = Collections.min(temperatureList);
System.out.println("Minimum temperature: "+min);
//Reverse the list
Collections.reverse(temperatureList);
System.out.println("Reversed List: "+temperatureList);
//Copy elements from one list to another
List<Double> temperatureList = new ArrayList<Double>(temperatureList.size());
newTemperatureList.add(13.6);
newTemperatureList.add(10.2);
newTemperatureList.add(42.9);
newTemperatureList.add(34.4);
newTemperatureList.add(27.2);
System.out.println("New temperature list: "+newTemperatureList);
Collections.copy(newTemperatureList, temperatureList);
System.out.println("New temperature list after copy: "+newTemperatureList);
Collections.replaceAll(temperatureList, 40.5, 0.0);
System.out.println("After replaceAll: "+temperatureList);
}
}
Implement all the method bodies using JAVA. Collection Selector Problem Overview This assignment focuses on implementing...
JAVA Question a) Write a generic method public static <...> Collection<Pair<...>> sortPairCollection(Collection <Pair<....>> col) in a Utils class that takes as parameter a collection of Pair<K,V> objects and returns a new collection object (use ArrayList<...>) with the pair elements from collection col sorted in ascending order. For comparing pairs, the K type must implement Comparable<....> Use the proper type constraints. b) Write a main() function in Utils.java that tests the sortPairCollection() with K=String and V=Integer.
this is a generic class in java how implement sort method public class ArrayBag<T> { private T[] data; private int manyItems; // TODO change and implement this method to use the generic type // Sort the elements based on the comparator passed to this method // You must use Selection Sort algorithm public void sort(Comparator<T> comp) { } }
Java implement the method in IteratorExercise.java using only list iterator methods: bubbleSort: sort the provided list using bubble sort Do not modify the test code in each function. You can look at that code for some ideas for implementing the methods. import java.lang.Comparable; import java.util.*; public class IteratorExercise { public static <E extends Comparable<? super E>> void bubbleSort(List<E> c) throws Exception { // first line to start you off ListIterator<E> iit = c.listIterator(), jit;...
Java, can you help me out thanks. CSCI 2120 Introduction For this assignment you will implement two recursive methods and write JUnit tests for each one. You may write all three methods in the same class file. You are required to write Javadoc-style documentation for all of your methods, including the test methods. Procedure 1) Write method!! a recursive method to compare two Strings using alphabetical order as the natural order (case insensitive, DO NOT use the String class built-in...
1 Overview For this assignment you are required to write a Java program that plays (n, k)-tic-tac-toe; (n, k)-tic- tac-toe is played on a board of size n x n and to win the game a player needs to put k symbols on adjacent positions of the same row, column, or diagonal. The program will play against a human opponent. You will be given code for displaying the gameboard on the screen. 2 The Algorithm for Playing (n, k)-Tic-Tac-Toe The...
1. Do the following a. Write a class Student that has the following attributes: - name: String, the student's name ("Last, First" format) - enrollment date (a Date object) The Student class provides a constructor that saves the student's name and enrollment date. Student(String name, Date whenEnrolled) The Student class provides accessors for the name and enrollment date. Make sure the class is immutable. Be careful with that Date field -- remember what to do when sharing mutable instance variables...
Recursively sorting an unbounded stack (java) in ascending order? (This assignment is only limited to stacks only, No other data structures are allowed) My professor gave us a hint on how to implement this, however she wants the comparable interface to be used. im not sure on how to do this. Hint: May want to use a public method that accepts the original stack and then creates the two additional stacks needed. This method then calls a private method that...
Write in Java Implement the parse method and test it by calling with three different strings and by printing the results. The Scanner method can be used to read values from strings, files, or System.in. We need to invoke the useDelimiter method to define what symbols can separate, or terminate, the digits of a Fraction. public static Fraction parse(String input) t Scanner s new Scanner(input) useDelimitercTVMitln"); int num s.nextlnt() int denom s.nextlnt); s.close): return new Fraction(num, denom) class Codechef static...
Implement a method to build an AVL tree out of a sorted (ascending order) array of unique integers, with the fastest possible big O running time. You may implement private helper methods as necessary. If your code builds a tree that is other than an AVL tree, you will not get any credit. If your code builds an AVL tree, but is not the fastest big O implementation, you will get at most 12 points. You may use any of...
The task of this project is to implement in Java Hash Table structure using Linear Probing Collision Strategy. You can assume that no duplicates or allowed and perform lazy deletion (similar to BST). Specification Create a generic class called HashTableLinearProbe <K,V>, where K is the key and V is the value. It should contain a private static class, HashEntry<K,V>. Use this class to create array to represent Hashtable: HashEntry<K,V> hashtable[]; Implement all methods listed below and test each method...