Sort Array with Customized Comparator in Java

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

2K+ Views

Let’s say the following is our string array and we need to sort it:String[] str = { "Tom", "Jack", "Harry", "Zen", "Tim", "David" };Within the sort() method, create a customized comparator to sort the above string. Here, two strings are compared with each other and the process goes on:Arrays.sort(str, new Comparator < String > () {    public int compare(String one, String two) {       int val = two.length() - one.length();       if (val == 0)       val = one.compareToIgnoreCase(two);       return val;    } });Exampleimport java.util.Arrays; import java.util.Comparator; public class Demo ... Read More

PHP and MySQL Database Connection and Table Creation

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

1K+ Views

To create database only once, use the below syntax.CREATE DATABASE IF NOT EXISTS yourDatabaseName;To create table only once, use the below syntax −CREATE TABLE IF NOT EXISTS yourTableName (    yourColumnName yourDatatype,    .    .    .    N );Let us implement both the above syntaxes to create database and table only once if does not already exist −mysql> CREATE DATABASE IF NOT EXISTS login; Query OK, 1 row affected (0.23 sec)Above query creates a database successfully.Following is the query to create a table −mysql> CREATE TABLE IF NOT EXISTS DemoTable (    Id int ); Query OK, 0 rows affected (0.56 sec)Above query creates a table successfully.

Reset MySQL Field to Default Value

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

2K+ Views

In MySQL, there are two approaches by which you can reset the MySQL field to default value. One is default keyword and another is default() function.Case 1: Using default keyword. The syntax is as follows:UPDATE yourTableName SET yourColumnName=default where yourCondition;Case 2: Using default() function. The syntax is as follows:UPDATE yourTableName SET yourColumnName=default(yourColumnName) where yourCondition;To understand the above syntax, let us create a table. The query to create a table is as follows:mysql> create table Default_Demo    -> (    -> Id int NOT NULL AUTO_INCREMENT,    -> Name varchar(20),    -> Age int,    -> Salary float,    -> PRIMARY ... Read More

Fix Java Math BigInteger Cannot Be Cast to Java Lang Integer

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

6K+ Views

You can typecast with the help of method intValue(). The syntax is as follows −Integer yourVariableName=((BigInteger) yourBigIntegerValue).intValue();Here is the Java code to convert java.math.BigInteger cast to java.lang.Integer. The code is as follows −Example Live Demoimport java.math.BigInteger; public class BigIntegerToInteger {    public static void main(String []args) {       BigInteger bigValue [] = new BigInteger[5];       bigValue[0] = new BigInteger("6464764");       bigValue[1] = new BigInteger("212112221122");       bigValue[2] = new BigInteger("76475");       bigValue[3] = new BigInteger("94874747");       bigValue[4] = new BigInteger("2635474");       for(int i = 0; i< bigValue.length; i++) ... Read More

Earliest Data Output Time in 8085 Microprocessor Considering TOE

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

177 Views

The 8085AH activates the RD* Signal at 270 nS. This signal moves to OE* pin of 27128 through the octal line driver 74LS241 delayed by 12nS. Hence the signal OE* signal is received by 27128 at the end of time 282 nS. Hence the data can only come out from the pins ranging from D7 to D0 of 27128 by 282 nS + tOE = 282 nS + 75 nS + 357 nS.From the discussion done previously it should be crystal clear that the earliest data output time should be 357 nS, by considering all the three parameters tACC, tCE, and ... Read More

Use Vector Class in Android ListView

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

308 Views

This example demonstrate about How to use vector class in Android listviewStep 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 the name and record number as Edit text, when user clicks on save button it will store the data into ArrayList. Click on ... Read More

Single and Multi-Tier Architectures of ODBC

Nancy Den
Updated on 30-Jul-2019 22:30:25

397 Views

Generally, ODBC architecture is of two types single-tier and multi-tier.Single-tier architectureThis is an ODBC architecture which involves single-tier ODBC drivers. In singletier ODBC architecture, the ODBC driver receives ODBC requests/calls from the application and directly interacts with database files. It passes the SQL commands corresponding to the received calls and retrieves the results.Example: Microsoft AccessMultiple-tier architectureThis is an ODBC architecture which involves multiple-tier ODBC drivers. This is a common architecture and is based on client server communication.Client: The application that makes ODBC requests, the driver and the DriverManager together considered as a client.Server: The database and the database software (that ... Read More

LocalDateTime isBefore Method in Java

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

182 Views

It can be checked if a particular LocalDateTime is before the other LocalDateTime in a timeline using the isBefore() method in the LocalDateTime class in Java. This method requires a single parameter i.e. the LocalDateTime object that is to be compared. It returns true if the LocalDateTime object is before the other LocalDateTime object and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Main {    public static void main(String[] args) {       LocalDateTime ldt1 = LocalDateTime.parse("2019-02-15T11:37:12");       LocalDateTime ldt2 = LocalDateTime.parse("2019-02-18T23:15:30");       System.out.println("The LocalDateTime ldt1 is: ... Read More

Make Custom Dialog with View Actions in Android

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

1K+ Views

This example demonstrate about How to make custom dialog with custom dialog view actions 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 button. When user click on button, it will show custom dialog.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.AlertDialog; import android.support.v7.app.AppCompatActivity; import android.view.LayoutInflater; import android.view.View; import android.view.ViewGroup; import android.widget.Button; public class ... Read More

Calculate Value from Multiple Columns in MySQL

Anvi Jain
Updated on 30-Jul-2019 22:30:25

1K+ Views

To calculate a value from multiple columns, use GROUP BY. Following is the syntax −select yourColumnName1, sum(yourColumnName2*yourColumnName3) AS anyAliasName from yourTableName group by yourColumnName1;Let us first create a table −mysql> create table calculateValueDemo    -> (    -> Id int,    -> ProductPrice int,    -> ProductWeight int    -> ); Query OK, 0 rows affected (0.56 sec)Following is the query to insert records in the table using insert command −mysql> insert into calculateValueDemo values(100, 35, 5); Query OK, 1 row affected (0.16 sec) mysql> insert into calculateValueDemo values(101, 50, 3); Query OK, 1 row affected (0.16 sec) ... Read More

Advertisements