Sort Elements in an ArrayList in Java

George John
Updated on 25-Jun-2020 14:40:21

4K+ Views

In order to sort elements in an ArrayList in Java, we use the Collections.sort() method in Java. This method sorts the elements available in the particular list of the Collection class in ascending order.Declaration −The java.util.Collections.sort() method is declared as follows −public static void sort(List list)where list is an object on which sorting needs to be performed.Let us see a program to sort elements in an ArrayList in Java −Example Live Demoimport java.util.*; public class Example {    public static void main (String[] args) {       List zoo = new ArrayList();       zoo.add("Zebra");       zoo.add("Lion"); ... Read More

Copy Elements of ArrayList to Java Vector

Chandu yadav
Updated on 25-Jun-2020 14:39:50

454 Views

In order to copy elements of ArrayList to Java Vector, we use the Collections.copy() method. It is used to copy all elements of a collection into another.Declaration −The java.util.Collections.copy() method is declared as follows −public static void copy(List

Local Inner Class in Java

Arjun Thakur
Updated on 25-Jun-2020 14:38:35

3K+ Views

In Java, just like methods, variables of a class too can have another class as its member. Writing a class within another is allowed in Java. The class written within is called the nested class, and the class that holds the inner class is called the outer class.SyntaxFollowing is the syntax to write a nested class. Here, the class Outer_Demo is the outer class and the class Inner_Demo is the nested class.class Outer_Demo {    class Inner_Demo {    } }Nested classes are divided into two types.Non-static nested classes − These are the non-static members of a class.Static nested classes ... Read More

Copy Elements of One ArrayList to Another in Java

Arjun Thakur
Updated on 25-Jun-2020 14:38:08

8K+ Views

In order to copy elements of ArrayList to another ArrayList, we use the Collections.copy() method. It is used to copy all elements of a collection into another.Declaration −The java.util.Collections.copy() method is declared as follows −public static void copy(List

Find Minimum Element of ArrayList with Java Collections

Chandu yadav
Updated on 25-Jun-2020 14:37:35

4K+ Views

In order to compute minimum element of ArrayList with Java Collections, we use the Collections.min() method. The java.util.Collections.min() returns the minimum element of the given collection. All elements must be mutually comparable and implement the comparable interface. They shouldn’t throw a ClassCastException.Declaration −The Collections.min() method is declared as follows −public static T min(Collection c)where c is the collection object whose minimum is to be found.Let us see a program to find the minimum element of ArrayList with Java collections −Example Live Demoimport java.util.*; public class Example {    public static void main (String[] args) {       List list ... Read More

CSS voice-stress Speech Media Property

Sreemaha
Updated on 25-Jun-2020 14:36:59

174 Views

Add adjustments to the speech with the voice-stress property like change pitch, how much loud it is, etc.The following is the syntax:voice-stress: normal | strong | moderate | none | reducedThe following example is to implement the voice-stress speech media property:p {    voice-stress: strong; }Above, I have set strong emphasis using the strong voice-stress property value.

Get Enumeration Over ArrayList with Java Collections

Arjun Thakur
Updated on 25-Jun-2020 14:36:46

619 Views

In order to get enumeration over ArrayList with Java Collections, we use the java.util.Collections.enumeration() method.Declaration −The java.util.Collections.enumeration() method is declared is as follows −public static Enumeration enumeration(Collection c)where c is the collection object for which an enumeration is returnedLet us see a program to get enumeration over ArrayList −Example Live Demoimport java.util.*; public class Example {    public static void main (String[] args) {       ArrayList list = new ArrayList();       list.add(14);       list.add(2);       list.add(73);       Enumeration en = Collections.enumeration(list); // getting enumeration over ArrayList list       ... Read More

CSS voice-volume Speech Media Property

Ankith Reddy
Updated on 25-Jun-2020 14:36:15

216 Views

Adjust the relative volume level using the voice-volume CSS property.The following is the syntax:voice-volume: [x-soft | soft | medium | loud | x-loud]The following is a code snippet for the voice-volume speech media property:p {    voice-volume: soft; }You can also set the volume in decibalsp {    voice-volume: 2dB; }Set both the voice-volume media property and volume level in decibals :p {    voice-volume: medium 3dB; }

Compare Two Short Arrays in a Single Line in Java

Ankith Reddy
Updated on 25-Jun-2020 14:36:14

331 Views

Two short arrays can be compared in Java using the java.util.Arrays.equals() method. This method returns true if the arrays are equal and false otherwise. The two arrays are equal if they contain the same number of elements in the same order.A program that compares two short arrays using the Arrays.equals() method is given as follows −Example Live Demoimport java.util.Arrays; public class Demo {    public static void main(String[] argv) throws Exception {       boolean flag = Arrays.equals(new short[] { 2, 8, 5 }, new short[] { 2, 8, 5 });       System.out.println("The two short arrays are equal? ... Read More

Perform Binary Search on ArrayList with Java Collections

George John
Updated on 25-Jun-2020 14:35:34

1K+ Views

In order to perform Binary Search on ArrayList with Java Collections, we use the Collections.binarySearch() method.Declaration −The java.util.Collections.binarySearch() method is declared as follows −public static int binarySearch(List list, T key)The above method returns the position of the key in the list sorted in ascending order. If we use a Comparator c to sort the list, the binarySearch() method will be declared as follows −public static int binarySearch(List list, T key, Comparator c)If key is not present, the it returns ((insertion point) + 1) *(-1).Let us see a program to perform binarySearch() on ArrayList −Example Live Demoimport java.util.*; public class Example { ... Read More

Advertisements