Karthikeya Boyini has Published 2383 Articles

Java Program to convert a Map to a read only map

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:25

202 Views

Let’s say the following is our Map −Mapmap = new HashMap(); map.put("1", "A"); map.put("2", "B"); map.put("3", "C");Make it read-only using the unmodifiableMap() method −map = Collections.unmodifiableMap(map);Example Live Demoimport java.util.Collections; import java.util.HashMap; import java.util.Map; public class Demo {    public static void main(String[] argv) throws Exception {       Mapmap = ... Read More

How to sort Map values by key in Java?

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:25

168 Views

Let’s say the following is our Map with unsorted keys −HashMapmap = new HashMap(); map.put("1", "A"); map.put("6", "B"); map.put("3", "C"); map.put("7", "D"); map.put("5", "E"); map.put("2", "F"); map.put("4", "G"); map.put("8", "H");Now, sort the above Map. The result of tMap below would be a sorted map by key −MaptMap = new TreeMap(map);Example Live ... Read More

How to use pollLast() in android ConcurrentLinkedDeque?

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:25

78 Views

Before getting into an example, we should know what ConcurrentLinkedDeque is, it is unbounded deque based on linked nodes. Multiple threads can access deque elements with safety.This example demonstrates about How to use pollLast() in android ConcurrentLinkedDequeStep 1 − Create a new project in Android Studio, go to File ⇒ ... Read More

MySQL query to check if database is empty or not?

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:25

2K+ Views

You can use INFORMATION_SCHEMA.COLUMNS to check if a database is empty or not. The syntax is as follows −SELECT COUNT(DISTINCT `TABLE_NAME`) AS anyAliasName FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `table_schema` = 'yourDatabaseName';The above syntax returns 0 if the database has notable otherwise it returns the number of tables. For our example, we are ... Read More

Java Program to insert a value to a SortedSet

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:25

113 Views

Let’s say we have the following SortedSet −SortedSet set = new TreeSet(); set.add("T"); set.add("R"); set.add("S"); set.add("Q"); set.add("V"); set.add("U"); set.add("W");Now, after displaying the above elements with Iterator, you can insert values like this to a SortedSetset.add("Z"); set.add("Y");Example Live Demoimport java.util.Iterator; import java.util.SortedSet; import java.util.TreeSet; public class Demo {    public static void ... Read More

C++ Program to Implement AVL Tree

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:25

20K+ Views

AVL tree is a self-balancing Binary Search Tree where the difference between heights of left and right subtrees cannot be more than one for all nodes.Tree rotation is an operation that changes the structure without interfering with the order of the elements on an AVL tree. It moves one node ... Read More

How to use pool() ArrayBlockingQueue in android?

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:25

83 Views

Before getting into an example, we should know what arrayblockingqueue is, it travels FIFO manner and the first element going to live the longest period of time and last element of the queue going to live a short period of the time.This example demonstrates about How to use pool() ArrayBlockingQueue ... Read More

Make a Hashtable read-only in Java

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:25

162 Views

Read-only Hashtable would mean users won’t be able to add or remove elements from it. Let us first create a Hashtable with key-value pair −Hashtablehash = new Hashtable(); hash.put("1", "A"); hash.put("2", "B"); hash.put("3", "C"); hash.put("4", "D"); hash.put("5", "E"); hash.put("6", "F"); hash.put("7", "G");Now, use unmodifiableMap() to form a Hashtable read-only −Mapm ... Read More

Get total in the last row of MySQL result?

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:25

484 Views

To get total in the last row of MySQL result, use the following syntax −(    SELECT yourColumnName1,    yourColumnName2,    yourColumnName3,    .    .    N    FROM yourTableName ) UNION (    SELECT "yourMessage" AS anyAliasName1,    SUM(yourColumnName1) AS anyAliasName2,    SUM(yourColumnName2) AS anyAliasName3,    .   ... Read More

How to use pop() in android ConcurrentLinkedDeque?

karthikeya Boyini

karthikeya Boyini

Updated on 30-Jul-2019 22:30:25

69 Views

Before getting into an example, we should know what ConcurrentLinkedDeque is, it is unbounded deque based on linked nodes. Multiple threads can access deque elements with safety.This example demonstrates about How to use pop() in android ConcurrentLinkedDequeStep 1 − Create a new project in Android Studio, go to File ⇒ ... Read More

Advertisements