Ankith Reddy has Published 996 Articles

How to update two columns in a MySQL database?

Ankith Reddy

Ankith Reddy

Updated on 30-Jun-2020 06:32:46

551 Views

You can update two columns using SET command separated with comma(, ). The syntax is as follows −UPDATE yourTableName SET yourColumnName1 = ’yourValue1’, yourColumnName2 = ’yourValue2’ where yourCondition;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table StudentInformations ... Read More

Find max and second max salary for a MySQL Employee table?

Ankith Reddy

Ankith Reddy

Updated on 30-Jun-2020 06:20:27

464 Views

You can get max and second max salary from an Employee table using LIMIT OFFSET. The syntax is as follows −SELECT yourColumnName1, yourColumnName2, ....N from yourTableName ORDER BY yourColumnName desc limit 2 offset 0;To understand the above syntax, let us create a table. The query to create a table is ... Read More

Get current time and date on Android

Ankith Reddy

Ankith Reddy

Updated on 30-Jun-2020 05:28:09

10K+ Views

As per Oracle documentation, SimpleDateFormat is a concrete class for formatting and parsing dates in a locale-sensitive manner. In this example, we have imported simple date format class from java as shown below -import java.text.SimpleDateFormat; import java.util.Date;Step 1 − Create a new project in Android Studio, go to File ⇒ ... Read More

Loop through a HashMap using an Iterator in Java

Ankith Reddy

Ankith Reddy

Updated on 29-Jun-2020 13:55:50

250 Views

An Iterator can be used to loop through a HashMap. The method hasNext( ) returns true if there are more elements in HashMap and false otherwise. The method next( ) returns the next key element in the HashMap and throws the exception NoSuchElementException if there is no next element.A program ... Read More

Iterate through a LinkedList in reverse direction using a ListIterator in Java

Ankith Reddy

Ankith Reddy

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

914 Views

A ListIterator can be used to traverse the elements in the forward direction as well as the reverse direction in a LinkedList. The method hasPrevious( ) in ListIterator returns true if there are more elements in the LinkedList while traversing in the reverse direction and false otherwise. The method previous( ... Read More

Iterate through elements of a LinkedList using a ListIterator in Java

Ankith Reddy

Ankith Reddy

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

241 Views

A ListIterator can be used to traverse the elements in the forward direction as well as the reverse direction in a LinkedList.The method hasNext( ) in ListIterator returns true if there are more elements in the LinkedList while traversing in the forward direction and false otherwise. The method next( ) ... Read More

Insert all elements of other Collection to Specified Index of Java ArrayList

Ankith Reddy

Ankith Reddy

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

344 Views

The elements of a Collection can be inserted at the specified index of the ArrayList using the method java.util.ArrayList.addAll(). This method has two parameters i.e. the specific index at which to start inserting the Collection elements in the ArrayList and the Collection itself.If there is an element already present at ... Read More

Get the last index of a particular element in an ArrayList in Java

Ankith Reddy

Ankith Reddy

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

815 Views

The last index of a particular element in an ArrayList can be obtained by using the method java.util.ArrayList.lastIndexOf(). This method returns the index of the last occurance of the element that is specified. If the element is not available in the ArrayList, then this method returns -1.A program that demonstrates ... Read More

Remove the last entry of the TreeMap in Java

Ankith Reddy

Ankith Reddy

Updated on 29-Jun-2020 13:38:04

811 Views

To remove the last entry of the TreeMap, use the pollLastEntry() method.Let us first create a TreeMap and add elementsTreeMap m = new TreeMap(); m.put(1, "India"); m.put(2, "US"); m.put(3, "Australia"); m.put(4, "Netherlands"); m.put(5, "Canada");Remove the last entry nowm.pollLastEntry()The following is an example to remove the last entry of the TreeMapExample Live ... Read More

Loop through ArrayList in Java

Ankith Reddy

Ankith Reddy

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

809 Views

The elements of the ArrayList can be accessed one by one by using a for loop. A program that demonstrates this is given as followsExample Live Demoimport java.util.ArrayList; import java.util.List; public class Demo {    public static void main(String[] args) {       ArrayList aList = new ArrayList();     ... Read More

Previous 1 ... 4 5 6 7 8 ... 100 Next
Advertisements