Initialize a Set without using add() method in Java

Samual Sam
Published on 11-Jan-2019 09:51:02
With Java, you can initialize a set without using add() method.For this create a string array −String arr[] = { "A", "B", "C", "D", "E"};Now, use Set and asList() method to initialize the above string array to our Set −Set s = new HashSet(Arrays.asList(arr));The following is an example to initialize ... Read More

NavigableMap put() Method in Java

karthikeya Boyini
Published on 11-Jan-2019 09:48:53
The NavigableMap put() method is used to set a specific key and value in the NavigableMap.The following is an example to implement NavigableMap put() method −Example Live Demoimport java.util.*; public class Demo { public static void main(String[] args) { NavigableMap<Integer, String> n ... Read More

Get lower key from NavigableMap in Java

Samual Sam
Published on 11-Jan-2019 09:47:03
To get lower key means returning the greatest key strictly less than the given key. This can be done using lowerKey() method.The following is an example to get lower key from NavigableMap −Example Live Demoimport java.util.*; public class Demo { public static void main(String[] args) { ... Read More

Remove value from HashMap in Java

karthikeya Boyini
Published on 11-Jan-2019 09:45:24
Use the remove() method to remove value from HashMap.First, create a HashMap and add elements −HashMap hm = new HashMap(); hm.put("Wallet", new Integer(700)); hm.put("Belt", new Integer(600)); hm.put("Backpack", new Integer(1200));Now, remove a value, let’s say with key “Wallet” −Object ob = hm.remove("Wallet");The following is an example to remove a value from ... Read More

Displaying content of a HashMap in Java

Samual Sam
Published on 11-Jan-2019 09:43:12
Let us first create a HashMap and add elements −HashMap hm = new HashMap(); hm.put("Wallet", new Integer(700)); hm.put("Belt", new Integer(600));To display the content, just print the HashMap object −System.out.println("Map = "+hm);The following is an example to display content of a HashMap −Example Live Demoimport java.util.*; public class Demo { ... Read More

Get the fields in each constraint in MySQL

Vrundesha Joshi
Published on 10-Jan-2019 17:59:22
Let’s say we have a database “business” with number of tables. If you want to Get the fields in each constraint, then use the below query.The below query is to get the fields in each one of those constraints −mysql> select * −> from information_schema.key_column_usage −> where constraint_schema = 'business';The ... Read More

Get a list of Constraints from MySQL Database?

Jennifer Nicholas
Published on 10-Jan-2019 17:40:29
To get a list of constraints from MySQL database, use the following syntax −select *from information_schema.table_constraints where constraint_schema = 'yourDatabaseName';Here, we will get the constraints from the database “business”. The following is the query to list the constraints of all the tables in the database “business” −mysql> select *   ... Read More

How to store Query Result in a variable using MySQL?

Anvi Jain
Published on 10-Jan-2019 17:39:02
To store query result in a variable with MySQL, use the SET command. The syntax is as follows −SET @anyVariableName = ( yourQuery);To understand the above concept, let us create a table. The following is the query to create a table −mysql> create table QueryResultDemo    −> (    −> ... Read More

Compare DATE string with string from MySQL DATETIME field?

Vrundesha Joshi
Published on 10-Jan-2019 17:37:06
You can compare DATE string with string from DATETIME field with the help of DATE() function in MySQL.The syntax is as follows −select *from yourTableName where DATE(yourColumnName) = ’anyDateString’;To understand the above syntax, let us create a table and set some datetime values in the table. The query to create ... Read More

Get the difference between two timestamps in seconds in MySQL?

Rishi Rathor
Published on 10-Jan-2019 17:35:08
To get difference between two timestamps in seconds, use two in-built functions TIME_TO_SEC() and TIMEDIFF() in MySQL. The syntax is as follows −select time_to_sec(timediff(yourCoulnName1, yourCoulnName2)) as anyVariableName from yourTableName;To understand the above concept, let us first create a table. The query to create a table.mysql> create table TimeToSecond ... Read More
Advertisements