Copy All Elements of Java LinkedHashSet to an Object Array

karthikeya Boyini
Updated on 30-Jul-2019 22:30:24

214 Views

First, create a LinkedHashSet and add elements −LinkedHashSet l = new LinkedHashSet(); l.add(new String("1")); l.add(new String("2")); l.add(new String("3")); l.add(new String("4")); l.add(new String("5")); l.add(new String("6")); l.add(new String("7"));Now, copy it to an object array like this −// copying Object[] arr = l.toArray();The following is an example to copy all elements of a LinkedHashSet to an object array −Example Live Demoimport java.util.*; public class Demo { public static void main(String[] args) { LinkedHashSet l = new LinkedHashSet(); l.add(new String("1")); l.add(new String("2")); ... Read More

MySQL Syntax: Not Evaluating with Not Equal Operator in Presence of Null

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:24

164 Views

Use the IS NOT NULL operator to compare with NULL values. The syntax is as follows −SELECT *FROM yourTableName where yourColumnName1 is not null or yourColumnName2 anyIntegerValue;To check the not equal to in presence of null, let us create a table. The query to create a table is as follows −mysql> create table IsNullDemo    −> (    −> ProductId int,    −> ProductName varchar(100),      −> ProductBackOrder int    −> ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table with null value to avoid the presence of null. The query to insert records ... Read More

Opt for EMI Option Using Debit Card on E-commerce Websites

Vihan Rodrigues
Updated on 30-Jul-2019 22:30:24

91 Views

The online market is worth millions at the moment and there is a complete generation who loves shopping online, especially on EMI. I also purchased a Smart Television on last Diwali and that too on EMIs and still paying. However, I have the satisfaction of giving this as a surprise gift to my ‘die-hard web series’ fan wife who wanted to enjoy the streaming on a larger screen.However, many folks among us get deprived of picking the most needful air-conditioner at the blazing summer or the latest 8th generation laptop for higher studies just because they carry mere a debit ... Read More

Replace Element at Specified Index of Vector in Java

Vikyath Ram
Updated on 30-Jul-2019 22:30:24

650 Views

An element in a Vector can be replaced at a specified index using the java.util.Vector.set() method. This method has two parameters i.e the index at which the Vector element is to be replaced and the element that it should be replaced with. Vector.set() method returns the element that was at the position specified at the index previously.A program that demonstrates this is given as follows:Example Live Demoimport java.util.Vector; public class Demo { public static void main(String args[]) { Vector vec = new Vector(5); vec.add(7); ... Read More

Recursive Factorial Method in Java

Rishi Raj
Updated on 30-Jul-2019 22:30:24

5K+ Views

The factorial of any non-negative integer is basically the product of all the integers that are smaller than or equal to it. The factorial can be obtained using a recursive method.A program that demonstrates this is given as follows:Example Live Demopublic class Demo {    public static long fact(long n) {       if (n

Remove Seconds from Time Field in MySQL

Arjun Thakur
Updated on 30-Jul-2019 22:30:24

2K+ Views

You need to use TIME_FORMAT() to remove seconds from time field. The syntax is as follows:SELECT TIME_FORMAT(yourColumnName1, "%H:%i") AS anyVariableName, TIME_FORMAT(yourColumnName2, "%H:%i") AS anyVariableName FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table removeSecondsFromTime    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> StartTime time,    -> EndTime time,    -> PRIMARY KEY(Id)    -> ); Query OK, 0 rows affected (0.71 sec)Insert some records in the table using insert command. The query is as follows:mysql> insert into removeSecondsFromTime(StartTime, EndTime) values('10:20:45', '11:21:40'); Query OK, ... Read More

Add Days to a Date in MySQL

Rishi Rathor
Updated on 30-Jul-2019 22:30:24

3K+ Views

To add days to a date, you can use DATE_ADD() function from MySQL. The syntax is as follows to add days to a date −INSERT INTO yourTableName VALUES(DATE_ADD(now(), interval n day));In the above syntax, you can use curdate() instead of now(). The curdate() will store only date while now() will store both date and time.Here is the demo of both the functions. To understand the above syntax, let us create a table.mysql> create table addingDaysDemo −> ( −> yourDateTime datetime −> ); Query OK, 0 rows affected (1.09 sec)Use both the ... Read More

Add Shadow Effect for Text in Android

Arjun Thakur
Updated on 30-Jul-2019 22:30:24

3K+ Views

This example demonstrates how to add shadow Effect for a Text in Android.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to create a new project.Step 2 − Add the following code to res/layout/activity_main.xml.     In the above code, we have taken a text view with shadow properties as shown below -android:shadowColor = "#000" android:shadowDx = "-2" android:shadowDy = "-2" android:shadowRadius = "1"In the above tags indicates about shadow color, Axis's(X, Y) and shadow radius for text view.Step 3 − Add the following code to src/MainActivity.javapackage ... Read More

Search an Element of Vector in Java

Jai Janardhan
Updated on 30-Jul-2019 22:30:24

688 Views

An element of a Vector can be searched using the method java.util.ArrayList.indexOf(). This method returns the index of the first occurrence of the element that is specified. If the element is not available in the Vector, then this method returns -1.A program that demonstrates this is given as follows:Example Live Demoimport java.util.Vector; public class Demo { public static void main(String args[]) { Vector vec = new Vector(5); vec.add(4); vec.add(1); vec.add(7); ... Read More

Demonstrate Private Access Modifier in Java

Arushi
Updated on 30-Jul-2019 22:30:24

182 Views

The data members and methods of a class can be accessed only from within their declared class if they are specified with the private access modifier. The keyword private is used to specify this modifier.A program that demonstrates the private access modifier in Java is given as follows:Example Live Democlass A {    private int a = 6;    public void printA() {       System.out.println("Value of a = " + a);    } } public class Demo {    public static void main(String args[]) {       A obj = new A();       obj.printA();    } ... Read More

Advertisements