Arjun Thakur has Published 1247 Articles

What is the best datatype for currencies in MySQL?

Arjun Thakur

Arjun Thakur

Updated on 30-Jun-2020 07:03:33

The best data type for currencies in MySQL is a DECIMAL. The syntax of DECIMAL data type is as follows −DECIMAL(TotalDigit, NumberOfDigitAfterDecimalPoint);To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table CurrenciesDemo    -> (    -> TotalPrice ... Read More

Get table column names in alphabetical order in MySQL?

Arjun Thakur

Arjun Thakur

Updated on 30-Jun-2020 06:31:17

To get the table column names in alphabetical order, you need to use ORDER BY. The syntax is as follows −SELECT anyReferenceName.COLUMN_NAME FROM INFORMATION_SCHEMA.COLUMNS anyReferenceName WHERE anyReferenceName.TABLE_NAME = ’yourTableName’ ORDER BY anyReferenceName.COLUMN_NAMEFirst, we need to get all the columns and then we need to use ORDER BY. In the above ... Read More

How to ORDER BY LIKE in MySQL?

Arjun Thakur

Arjun Thakur

Updated on 30-Jun-2020 06:19:10

To order by like in MySQL, use the case statement. The syntax is as follows −SELECT *FROM yourTableName    ORDER BY CASE    WHEN yourColumnName like '%yourPatternValue1%' then 1    WHEN yourColumnName like '%yourPatternValue2%' then 2 else 3 end;To understand the above syntax, let us create a table. The query ... Read More

Use Iterator to remove an element from a Collection in Java

Arjun Thakur

Arjun Thakur

Updated on 29-Jun-2020 13:54:59

An element can be removed from a Collection using the Iterator method remove(). This method removes the current element in the Collection. If the remove() method is not preceded by the next() method, then the exception IllegalStateException is thrown.A program that demonstrates this is given as follows.Example Live Demoimport java.util.ArrayList; import ... Read More

Obtain the Previous Index and Next Index in an ArrayList using the ListIterator in Java

Arjun Thakur

Arjun Thakur

Updated on 29-Jun-2020 13:48:53

The previous index and next index in an ArrayList can be obtained using the methods previousIndex() and nextIndex() respectively in the ListIterator Interface.The previousIndex() method returns the index of the element that is returned by the previous() method while the nextIndex() method returns the index of the element that is ... Read More

Convert LinkedList to an array in Java

Arjun Thakur

Arjun Thakur

Updated on 29-Jun-2020 13:45:46

A LinkedList can be converted into an Array in Java using the method java.util.LinkedList.toArray(). This method has a single parameter i.e. the Array into which the LinkedList elements are to stored and it returns the Array with all the LinkedList elements in the correct order.A program that demonstrates this is ... Read More

Get the unmodifiable view of the specified ArrayList in Java

Arjun Thakur

Arjun Thakur

Updated on 29-Jun-2020 13:42:25

The unmodifiable view of the specified ArrayList can be obtained by using the method java.util.Collections.unmodifiableList(). This method has a single parameter i.e. the ArrayList and it returns the unmodifiable view of that ArrayList.A program that demonstrates this is given as followsExample Live Demoimport java.util.ArrayList; import java.util.ArrayList; import java.util.Collections; import java.util.List; public ... Read More

Check for the existence of a key in Java IdentityHashMap

Arjun Thakur

Arjun Thakur

Updated on 29-Jun-2020 13:20:52

Use the containsKey() method to check whether a particular key exists in IdentityHashMap or not.Create a IdentityHashMapMap m = newIdentityHashMap(); m.put("1", 100); m.put("2", 200); m.put("3", 300); m.put("4", 150); m.put("5", 110); m.put("6", 50); m.put("7", 90); m.put("8", 250); m.put("9", 350); m.put("10", 450);Now, let’s say we need to check whether key 7 exists ... Read More

Fetch the value for a specific key in Java IdentityHashMap

Arjun Thakur

Arjun Thakur

Updated on 29-Jun-2020 13:10:08

To fetch the value for a specific key, use the get() method.As a parameter, set the key you want to fetch and fetch the value.Let’s say you need to fetch value of key 3get("3")The following is an example to fetch the value for a specific key in Java IdentityHashMap −Example Live ... Read More

How to add a NOT NULL column in MySQL?

Arjun Thakur

Arjun Thakur

Updated on 29-Jun-2020 13:01:56

You can add a not null column at the time of table creation or you can use it for an existing table.Case 1 − Add a not null column at the time of creating a table. The syntax is as followsCREATE TABLE yourTableName (    yourColumnName1 dataType NOT NULL,   ... Read More

Previous 1 ... 3 4 5 6 7 ... 125 Next
Advertisements