Krantik Chavan has Published 308 Articles

Change the file extension in the text column in MySQL?

Krantik Chavan

Krantik Chavan

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

344 Views

To change the file extension in the text column, you can use UPDATE command along with REPLACE() function. Let’s say we have some columns with extensions and we need to replace all of them. For that, let us first create a table with the extension columns set as text type:mysql ... Read More

Java Program to create a TreeSet with custom Comparator

Krantik Chavan

Krantik Chavan

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

218 Views

To create a TreeSet with custom comparator, let us first create a an Integer array and set it to TreeSetInteger arr[] = { 10, 20, 30, 40, 50, 60, 70, 80, 90, 100 }; Set set = new TreeSet(Collections.reverseOrder());Above, we have used the Comparator with reverseOrder(), which returns a comparator ... Read More

Display a TreeSet in reverse order in Java

Krantik Chavan

Krantik Chavan

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

250 Views

To display a TreeSet in reverse order, you need to use Comparator. Let us first create an Integer array and use it for the TreeSet elements:Integer arr[] = { 25, 100, 125, 200, 250, 400, 450, 550, 600, 700};Now, use reverseOrde() comparator to reverse the natural ordering:Set set = new ... Read More

Get records in a certain order using MySQL?

Krantik Chavan

Krantik Chavan

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

76 Views

You can use ORDER BY IF() to get records in a certain order. Let us first create a table:mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    FirstName varchar(20),    Branch varchar(20) ); Query OK, 0 rows affected (1.96 sec)Following is the query to insert ... Read More

Java Program to get headset from TreeSet

Krantik Chavan

Krantik Chavan

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

83 Views

To get HeadSet from TreeSet, at first create a TreeSet and add some elements:TreeSet treeSet = new TreeSet(); treeSet.add("ABC"); treeSet.add("DEF"); treeSet.add("GHI"); treeSet.add("JKL"); treeSet.add("MNO"); treeSet.add("PQR");To get headset, use the headset() method:SortedSet set = treeSet.headSet("MNO"); System.out.println("Head Set = " + set);You can also change the value like this:set = treeSet.headSet("GHI"); System.out.println("Head Set ... Read More

Java Program to get the lowest and highest value in TreeSet

Krantik Chavan

Krantik Chavan

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

1K+ Views

Create a TreeSet first to get the lowest and highest value:TreeSet treeSet = new TreeSet();Add elements to the TreeSet:treeSet.add(50); treeSet.add(100); treeSet.add(150); treeSet.add(200); treeSet.add(250); treeSet.add(300); treeSet.add(400); treeSet.add(500); treeSet.add(800); treeSet.add(1000);Now, get the lowest value and highest value from the above TreeSet, which are 50 and 1000 respectively:treeSet.first(); treeSet.last();Exampleimport java.util.TreeSet; public class Demo ... Read More

How to get the greatest of two columns values in MySQL?

Krantik Chavan

Krantik Chavan

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

223 Views

In order to get the greatest of two columns values in MySQL, you need to use GREATEST() function. Following is the syntax:select greatest(yourColumnName1, yourColumnName2) AS anyAliasName from yourTableName; Let us first create a table:mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    Number1 int,    Number2 ... Read More

C++ Program to Implement Sieve of Atkin to Generate Prime Numbers Between Given Range

Krantik Chavan

Krantik Chavan

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

372 Views

This is C++ program to implement Sieve of Atkin to Generate Prime Numbers Between Given Range. The Sieve of Atkin is a modern algorithm for finding all prime numbers up to a specified integer.AlgorithmBegin    Create a results list, filled with 2, 3, and 5.    Initialize the sieve array ... Read More

C++ Program to Implement Segmented Sieve to Generate Prime Numbers Between Given Range

Krantik Chavan

Krantik Chavan

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

759 Views

This is C++ program to implement Segmented Sieve to Generate Prime Numbers Between Given Range. Segmented Sieve first uses Simple Sieve to find primes smaller than or equal to √(n). The idea of this algorithm is to divide the range [0 ... n-1] in different segments and compute primes in ... Read More

Is it mandatory to close JDBC connections?

Krantik Chavan

Krantik Chavan

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

2K+ Views

At the end of your JDBC program, it is required explicitly to close all the connections to the database to end each database session. However, if you forget, Java's garbage collector will close the connection when it cleans up stale objects.Relying on the garbage collection, especially in database programming, is ... Read More

Advertisements