George John has Published 1081 Articles

Sort Elements in an ArrayList in Java

George John

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 ... Read More

Perform Binary Search on ArrayList with Java Collections

George John

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 ... Read More

Moving a file from one directory to another using Java

George John

George John

Updated on 25-Jun-2020 14:32:50

6K+ Views

We can use Files.move() API to move file from one directory to another. Following is the syntax of the move method.public static Path move(Path source, Path target, CopyOption... options) throws IOExceptionWheresource − Source path of file to be movedtarget − Target path of file to be movedoptions − options like ... Read More

Shuffle elements of ArrayList with Java Collections

George John

George John

Updated on 25-Jun-2020 14:32:41

3K+ Views

In order to shuffle elements of ArrayList with Java Collections, we use the Collections.shuffle() method. The java.util.Collections.shuffle() method randomly permutes the list using a default source of randomness.Declaration −The java.util.Collections.shuffle() method is declared as follows −public static void shuffle(List list)Let us see a program to shuffle elements of ArrayList ... Read More

Object Serialization with inheritance in Java

George John

George John

Updated on 25-Jun-2020 14:27:13

3K+ Views

In Serialization when inheritance is introduced then on the basis of superclass and subclass certain cases have been defined which make the understanding of Serialization in each case much simpler. The fundamental rules which should be followed are as below.1. When super class is implements Serializable interface and subclass is ... Read More

Java program to print duplicates from a list of integers

George John

George John

Updated on 25-Jun-2020 14:23:39

4K+ Views

In order to find duplicates we can utilize the property of Set in Java that in Java duplicates are not allowed when going to be added in a Set.Add method of set returns true for the adding value which is not added previously to it while it would return false ... Read More

Sorting a HashMap according to keys in Java

George John

George John

Updated on 25-Jun-2020 14:13:27

2K+ Views

As we know that Hash map in Java does not maintain insertion order either by key or by order.Also it does not maintain any other order while adding entries to it.But Java provide another API named as TreeMap which maintain its insertion order sorted according to the natural ordering of ... Read More

Java program to accept the strings which contain all vowels

George John

George John

Updated on 25-Jun-2020 14:11:08

462 Views

In order to find that a given string contains all vowels we have to first convert given string into character array so that we can simplify the comparison of each character of given string.After this put each character into a hash map so that we can check whether our map ... Read More

Get Month Name from Month number in MySQL?

George John

George John

Updated on 25-Jun-2020 14:09:10

5K+ Views

You can use MONTHNAME() function from MySQL to display Month name from number. The syntax is as follows.SELECT MONTHNAME(STR_TO_DATE(yourColumnName, ’%m’)) as anyVariableName from yourTableName;To understand the above concept, let us first create a table. The query to create a table is as follows.mysql> create table MonthDemo -> ( -> MonthNum ... Read More

POJO vs Java Beans

George John

George John

Updated on 25-Jun-2020 14:07:32

5K+ Views

As we know that in Java POJO refers to the Plain old Java object.POJO and Bean class in Java shares some common features which are as follows −Both classes must be public i.e accessible to all.Properties or variables defined in both classes must be private i.e. can't be accessed directly.Both ... Read More

Advertisements