George John has Published 1167 Articles

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

5K+ 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

2K+ 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

Work with ZIP archives in Python (zipfile)

George John

George John

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

795 Views

The ZIP is one of the most popular file formats used for archiving and compression. It has been in use since the days of MSDOS and PC and has been used by famous PKZIP application.The zipfile module in Python’s standard library provides classes that facilitate the tools for creating, extracting, ... 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

Java Program to Print all unique words of a String

George John

George John

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

1K+ Views

To find unique words in a string use Map utility of java because of its property that it does not contain duplicate keys.In order to find unique words first get all words in array so that compare each word, for this split string on the basis of space/s.If other characters ... Read More

Sorting a HashMap according to keys in Java

George John

George John

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

1K+ 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

318 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

4K+ 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

Advertisements