What is a Unit class in JavaTuples?

Samual Sam
Updated on 30-Jul-2019 22:30:25
A Unit class is a Tuple of one element. It is in the JavaTuples library.The following is the declaration −public final class Unit extends Tuple implements IValue0Let us first see what we need to work with JavaTuples. To work with Unit class in JavaTuples, you need to import the following package −import org.javatuples.Unit;Some of its features include −TypesafeSerializableComparableIterableImmutableLet us see an example to create Unit Tuple in Java −Note − Steps to download and run JavaTuples program. If you are using Eclipse IDE, then Right Click Project -> Properties -> Java Build Path -> Add External Jars and upload the ... Read More

How to use trim () in Android sqlite?

Nishtha Thakur
Updated on 30-Jul-2019 22:30:25
Before getting into example, we should know what sqlite data base in android is. SQLite is an open source SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation. SQLite supports all the relational database features. In order to access this database, you don't need to establish any kind of connections for it like JDBC, ODBC etc.This example demonstrate about How to use trim () in Android sqliteStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to ... Read More

Best way to change the date format in MySQL SELECT?

George John
Updated on 30-Jul-2019 22:30:25
The best way to change the date format in MySQL SELECT is as followsSELECT DATE_FORMAT(yourColumnName, "%d/%m/%Y %H:%i") AS anyAliasName FROM yourTableName WHERE yourCondition;To understand the above concept, let us create a table. The query to create a table is as followsmysql> create table bestDateFormatDemo - > ( - > Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, - > ArrivalDateTime datetime - > ); Query OK, 0 rows affected (0.64 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into bestDateFormatDemo(ArrivalDateTime) values(now()); Query OK, ... Read More

LocalDate minusDays() Method in Java

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25
An immutable copy of the LocalDate where the days are subtracted from it can be obtained using the minusDays() method in the LocalDate class in Java. This method requires a single parameter i.e. the number of days to be subtracted and it returns the instant with the subtracted days.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { LocalDate ld1 = LocalDate.parse("2019-02-14"); System.out.println("The LocalDate is: " + ld1); ... Read More

Instant atZone() method in Java

Nancy Den
Updated on 30-Jul-2019 22:30:25
An Instant can be combined with a timezone to create a ZonedDateTime object using the atZone() method in the Instant class in Java. This method requires a single parameter i.e. the ZoneID and it returns the ZonedDateTime object.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Demo {    public static void main(String[] args) {       Instant i = Instant.parse("2019-01-13T18:35:19.00Z");       System.out.println("The Instant object is: " + i);       ZonedDateTime zdt = i.atZone(ZoneId.of("Australia/Melbourne"));       System.out.println("The ZonedDateTime object is: " + zdt);    } }OutputThe Instant object is: 2019-01-13T18:35:19Z ... Read More

Create view in MySQL only if it does not already exist?

Samual Sam
Updated on 30-Jul-2019 22:30:25
To create a view only if it does not already exist, you can use the following syntax −CREATE OR REPLACE VIEW yourViewName AS SELECT *FROM yourTableName;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table createViewDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Name varchar(20)    -> ); Query OK, 0 rows affected (0.58 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into createViewDemo(Name) values('John'); Query OK, 1 row affected (0.22 sec) mysql> insert into ... Read More

Lambda expression in C++

Ankith Reddy
Updated on 30-Jul-2019 22:30:25
C++ STL includes useful generic functions like std::for_each. Unfortunately they can also be quite cumbersome to use, particularly if the functor you would like to apply is unique to the particular function. So this function that you'll create will be in that namespace just being used at that one place. The solution to this is using anonymous functions.C++ has introduced lambda expressions in C++11 to allow creating anonymous function. For example, Example Live Demo#include #include #include // for_each using namespace std; int main() {    vector myvector;    myvector.push_back(1);    myvector.push_back(2);    myvector.push_back(3);    for_each(myvector.begin(), myvector.end(), [](int x) {   ... Read More

Virtual Constructor in C++

Jennifer Nicholas
Updated on 30-Jul-2019 22:30:25
The virtual mechanism works only when we have a base class pointer to a derived class object.In C++, the constructor cannot be virtual, because when a constructor of a class is executed there is no virtual table in the memory, means no virtual pointer defined yet. So, the constructor should always be non-virtual.But virtual destructor is possible.Example Code#include using namespace std; class b {    public:       b() {          cout

Pull and add to set at the same time with MongoDB? Is it Possible?

Arjun Thakur
Updated on 30-Jul-2019 22:30:25
Yes, you can use pull and add at the same time with $addToSet and $pull operator. Let us first create a collection with documents> db.pullAndAddToSetDemo.insertOne({StudentScores : [78, 89, 90]} ... ); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9a797e15e86fd1496b38af") }Following is the query to display all documents from a collection with the help of find() method> db.pullAndAddToSetDemo.find().pretty();This will produce the following output{    "_id" : ObjectId("5c9a797e15e86fd1496b38af"),    "StudentScores" : [       78,       89,       90    ] }Following is the query to pull and addtoset at the same time in MongoDB> var ... Read More

Java Program to convert LocalDateTime to java.util.Date

karthikeya Boyini
Updated on 30-Jul-2019 22:30:25
Set the LocalDateTime to current datetime −LocalDateTime dateTime = LocalDateTime.now();Create an Instant −Instant i = dateTime.atZone(ZoneId.systemDefault()).toInstant(); Convert LocalDateTime to java.util.Date: java.util.Date date = Date.from(i);Example Live Demoimport java.time.Instant; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.Date; public class Demo {    public static void main(String[] args) {       LocalDateTime dateTime = LocalDateTime.now();       Instant i = dateTime.atZone(ZoneId.systemDefault()).toInstant();       System.out.println("Instant = "+i);       java.util.Date date = Date.from(i);       System.out.println("Date = "+date);    } }OutputInstant = 2019-04-19T04:34:31.271973Z Date = Fri Apr 19 10:04:31 IST 2019
Advertisements