Get Last Value in Java TreeSet

Samual Sam
Updated on 30-Jul-2019 22:30:24

637 Views

To get the last value in TreeSet, use the last() method.First, get the TreeSet and add elements to it −TreeSet tSet = new TreeSet(); tSet.add("10"); tSet.add("20"); tSet.add("30"); tSet.add("40"); tSet.add("50"); tSet.add("60");Now, get the first value −tSet.last()The following is an example to get the last value in TreeSet −Example Live Demoimport java.util.*; public class Demo {   public static void main(String args[]){ TreeSet tSet = new TreeSet(); tSet.add("10"); tSet.add("20"); tSet.add("30"); ... Read More

What Does an Interface Consist of in Java

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

316 Views

An interface can be defined using the interface keyword. It contains variables and methods like a class but the methods in an interface are abstract by default unlike a class. An interface is primarily used to implement abstraction and it cannot be instantiated.A program that demonstrates an interface in Java is given as follows:Example Live Demointerface AnimalSound {    abstract void sound(); } class CatSound implements AnimalSound {    public void sound() {       System.out.println("Cat Sound: Meow");    } } class DogSound implements AnimalSound {    public void sound() {       System.out.println("Dog Sound: Bark");    } } ... Read More

Multiple Insert or Batch Insert in MySQL Query

George John
Updated on 30-Jul-2019 22:30:24

508 Views

You need to use VALUES() with comma separation for multiple insert or batch insert at a time. Use the following syntax that does not produce an invalid MySQL query on insert. The syntax is as follows:INSERT INTO yourTableName VALUES(yourValue1), (yourValue1), (yourValue2), (yourValue3), (yourValue4), (yourValue5), .......N;To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table addMultipleValues    -> (    -> Counter int NOT NULL    -> ); Query OK, 0 rows affected (0.60 sec)Now you can insert batch records in the table using VALUES() with comma separation. The query ... Read More

Describe All Tables in a Database Using a Single Statement in MySQL

Ankith Reddy
Updated on 30-Jul-2019 22:30:24

2K+ Views

You can use INFORMATION_SCHEMA.COLUMNS to describe all tables in database through a single statement. The syntax is as follows.SELECT *FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_SCHEMA=’yourDatabaseName’\GHere I am using my database sample with two tables.The table names are as follows −mytableyourtableImplement the above syntax for your database. The query is as follows −mysql> select * FROM information_schema.columns WHERE table_schema = 'sample'\GThe following is the output describing the two tables in our database.*************************** 1. row *************************** TABLE_CATALOG: def TABLE_SCHEMA: sample TABLE_NAME: mytable COLUMN_NAME: id ORDINAL_POSITION: 1 COLUMN_DEFAULT: NULL IS_NULLABLE: YES DATA_TYPE: int CHARACTER_MAXIMUM_LENGTH: NULL CHARACTER_OCTET_LENGTH: NULL NUMERIC_PRECISION: 10 NUMERIC_SCALE: 0 DATETIME_PRECISION: NULL CHARACTER_SET_NAME: NULL ... Read More

Extract First Word from a Field in MySQL

Vrundesha Joshi
Updated on 30-Jul-2019 22:30:24

4K+ Views

To extract first word from a field, use in-built SUBSTRING_INDEX() function. The syntax is as follows −SELECT SUBSTRING_INDEX(yourColumnName, ’ ‘, 1) as anyVariableName from yourTableName;In the above query, if you use -1 in place of 1 then you will get the last word. To understand the above concept, let us create a table. The following is the query to create a table.mysql> create table FirstWordDemo −> ( −> AllWords longtext −> ); Query OK, 0 rows affected (0.83 sec)Now insert some words in the table using insert command. The query is ... Read More

Determine if Running on a Rooted Device in Android

George John
Updated on 30-Jul-2019 22:30:24

3K+ Views

In some cases, we should not allow application should run on rooted devices for payment gateways. This example demonstrates how to determine if running on a rooted device or not.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. It contains information about root.Step 3 − Add the following code to src/MainActivity.javapackage com.example.andy.myapplication; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.widget.TextView; ... Read More

Conditional Select Between Dates in MySQL for Price Values

Ankith Reddy
Updated on 30-Jul-2019 22:30:24

682 Views

You need to use CASE statement to conditional select between dates to find the minimum and maximum price. Wrap up the CASE statement with aggregate function MIN() and MAX(). The syntax is as follows:SELECT MIN(CASE WHEN CURDATE() BETWEEN yourStartDateColumnName AND yourEndDateColumnName THEN yourLowPriceColumnName ELSE yourHighPriceColumnName END) AS anyVariableName, MAX(CASE WHEN CURDATE() BETWEEN yourStartDateColumnName AND yourEndDateColumnName THEN yourLowPriceColumnName ELSE yourHighPriceColumnName END) 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 ConditionalSelect    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> StartDate datetime, ... Read More

Comparison of Intel 8080 with Intel 8085

Ankith Reddy
Updated on 30-Jul-2019 22:30:24

907 Views

The Intel 8080 microprocessor was the predecessor of the 8085 or the Z-80 microprocessors. It was designed and manufactured by Intel. This Microprocessor was released on April 1974. It was an 8-bit Microprocessor.The Intel 8085 is also an 8-bit Microprocessor, which was introduced in 1976. It is very close to the 8080 microprocessor, but some slight changes and modifications are present. The Zilog Z-80 was also introduced in 1976. Basically, the Intel team was divided and formed a new Group called Zilog. The Zilog team was introduced the Z-80 Microprocessor.The 8080 MicroprocessorIn this diagram, we can see that the 8080 ... Read More

Remove Lowest Element in Java TreeSet

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

647 Views

To remove the lowest element, use the pollFirst() method.Create a TreeSet and add elements to it −TreeSet tSet = new TreeSet(); tSet.add("78"); tSet.add("56"); tSet.add("88"); tSet.add("12");Now, remove the lowest element −tSet.pollFirst()The following is an example to remove lowest element in Java TreeSet −Example Live Demoimport java.util.*; public class Demo { public static void main(String args[]){ TreeSet tSet = new TreeSet(); tSet.add("78"); tSet.add("56"); tSet.add("88"); tSet.add("12"); ... Read More

Get Custom Circle Button in Android

Ankith Reddy
Updated on 30-Jul-2019 22:30:24

6K+ Views

This example demonstrates how to get Custom circle button 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/actiivity_main.xml.     In the above code, we have taken the button with a round_button background. so create round_button.xml in drawable folder and add the following code.                                                   ... Read More

Advertisements