Task 4: Collections class public static void main(String[] args) { String[] colors = {"red", "green", "blue"}; ArrayList
Posted: Wed Apr 27, 2022 3:30 pm
Task 4: Collections class
public static void main(String[] args)
{
String[] colors =
{"red", "green", "blue"};
ArrayList<String> Colorslist = new ArrayList<>(Arrays.asList(colors));
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.Arrays;
public class Test
{
public static void main(String[] args)
{
Integer[] myNumbers =
{3, 5, 95, 4, 15, 34, 3, 6, 5};
ArrayList<Integer> list = new ArrayList<>(Arrays.asList(myNumbers));
//finding
the maximum
System.out.println("The
maximum is " + Collections.max(list));
//write
a code to the minimum number in myNumbers list
………………………………………………………………………………………………………..
//shuffling
the list
System.out.println("This
is shuffled");
//use
the method shuffle() to shuffle the elements in the list
…………………………………………………………………………………………………………………………………………………
System.out.println(list);
//sorting
the list
System.out.println("This
is sorted");
//use
the method sort() in java.util.Collection to sort
the elements in the list
…………………………………………………………………………………………………………………………………………………
System.out.println(list);
}}
public static void main(String[] args)
{
String[] colors =
{"red", "green", "blue"};
ArrayList<String> Colorslist = new ArrayList<>(Arrays.asList(colors));
}
import java.util.ArrayList;
import java.util.Collections;
import java.util.Arrays;
public class Test
{
public static void main(String[] args)
{
Integer[] myNumbers =
{3, 5, 95, 4, 15, 34, 3, 6, 5};
ArrayList<Integer> list = new ArrayList<>(Arrays.asList(myNumbers));
//finding
the maximum
System.out.println("The
maximum is " + Collections.max(list));
//write
a code to the minimum number in myNumbers list
………………………………………………………………………………………………………..
//shuffling
the list
System.out.println("This
is shuffled");
//use
the method shuffle() to shuffle the elements in the list
…………………………………………………………………………………………………………………………………………………
System.out.println(list);
//sorting
the list
System.out.println("This
is sorted");
//use
the method sort() in java.util.Collection to sort
the elements in the list
…………………………………………………………………………………………………………………………………………………
System.out.println(list);
}}