This example demonstrates How to enable back button action in the action bar.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.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.annotation.SuppressLint; import android.app.ActivityManager; import android.app.admin.DevicePolicyManager; import android.content.ComponentName; import android.content.Context; import android.content.Intent; import android.net.wifi.WifiInfo; import android.net.wifi.WifiManager; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.view.MenuItem; import android.view.View; import android.widget.TextView; public class ... Read More
The hash code value of the MonthDay can be obtained using the hashCode() method in the MonthDay class in Java. This method requires no parameters and it returns the hash code value of the MonthDay.A program that demonstrates this is given as followsExample Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { MonthDay md = MonthDay.parse("--02-21"); System.out.println("The MonthDay is: " + md); System.out.println("The hash code is: " + md.hashCode()); } }outputThe MonthDay is: --02-21 The hash code is: 149Now let us understand the above program.First ... Read More
The findAny() method of the IntStream class in Java is used to return an OptionalInt describing some element of the stream, or an empty OptionalInt if the stream is empty.The syntax is as follows −OptionalInt findAny()Here, OptionalInt is a container object which may or may not contain an int value.Create an IntStream and add some elements −IntStream intStream = IntStream.of(20, 35, 50, 60, 80, 100);Now, return any of the element of the stream using findAny() in Java −OptionalInt res = intStream.findAny();The following is an example to implement IntStream findAny() method in Java −Example Live Demoimport java.util.*; import java.util.stream.IntStream; public class ... Read More
Update date of datetime field with the help of arithmetic operator minus(-).The syntax is as followsupdate yourTableName set yourDateTimeColumnName=yourDateTimeColumnName - interval yourValue day where date(yourDateTimeColumnName)=’yourDateValue’;To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table updateDateDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> ArrivalDate datetime -> ); Query OK, 0 rows affected (0.66 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into updateDateDemo(ArrivalDate) values('2011-01-13'); Query OK, 1 row affected (0.19 sec) mysql> insert into updateDateDemo(ArrivalDate) values('2013-04-21'); ... Read More
You can use updateMany() to update documents. Let us create a collection with a document. The query to create a collection with a document is as follows −> db.updateManyDocumentsDemo.insertOne({"StudentName":"John", "StudentLastName":"Smith"}); { "acknowledged" : true, "insertedId" : ObjectId("5c948edd4cf1f7a64fa4df48") } > db.updateManyDocumentsDemo.insertOne({"StudentName":"John", "StudentLastName":"Doe"}); { "acknowledged" : true, "insertedId" : ObjectId("5c948ee64cf1f7a64fa4df49") } > db.updateManyDocumentsDemo.insertOne({"StudentName":"Carol", "StudentLastName":"Taylor"}); { "acknowledged" : true, "insertedId" : ObjectId("5c948ef14cf1f7a64fa4df4a") } > db.updateManyDocumentsDemo.insertOne({"StudentName":"David", "StudentLastName":"Miller"}); { "acknowledged" : true, "insertedId" : ObjectId("5c948f044cf1f7a64fa4df4b") }Display all documents from a collection with the help of find() method. The query is as follows −> db.updateManyDocumentsDemo.find().pretty();The following is the ... Read More
The unordered_multimap rehash(N) function in C++ STL sets the number of buckets in the container to n or more. A rehash is forced if n is greater than the current number of buckets in the container. The new bucket count can either be equal to or greater than n. The function may have no effect on the bucket count and may not force a rehash if n is lower than the current number of buckets in the container. Rehash () returns nothing and take n as a parameter which specifies the minimum number of buckets for the container hash table.AlgorithmBegin ... Read More
The MongoDB equivalent of WHERE IN(1, 2, ....) is $in operator. The syntax is as followsdb.yourCollectionName.find({yourFieldName:{$in:[yourValue1, yourValue2, ....N]}}).pretty();Let us first create a collection with documents> db.whereInDemo.insertOne({"StudentName":"John", "StudentMathScore":57}); { "acknowledged" : true, "insertedId" : ObjectId("5ca281ec6304881c5ce84ba5") } > db.whereInDemo.insertOne({"StudentName":"Larry", "StudentMathScore":89}); { "acknowledged" : true, "insertedId" : ObjectId("5ca281f56304881c5ce84ba6") } > db.whereInDemo.insertOne({"StudentName":"Chris", "StudentMathScore":98}); { "acknowledged" : true, "insertedId" : ObjectId("5ca281fd6304881c5ce84ba7") } > db.whereInDemo.insertOne({"StudentName":"Robert", "StudentMathScore":99}); { "acknowledged" : true, "insertedId" : ObjectId("5ca2820a6304881c5ce84ba8") } > db.whereInDemo.insertOne({"StudentName":"Bob", "StudentMathScore":97}); { "acknowledged" : true, "insertedId" : ObjectId("5ca282206304881c5ce84ba9") }Following is the query to display all documents from a collection with ... Read More
To skip blank and null in MySQL, use the following syntax:select *from yourTableName where yourColumnName IS NOT NULL AND yourColumnName '';Let us first create a table:mysql> create table DemoTable (Id int, FirstName varchar(20)); Query OK, 0 rows affected (0.66 sec)Following is the query to insert records in the table using insert command:mysql> insert into DemoTable values(100, 'Larry'); Query OK, 1 row affected (0.14 sec) mysql> insert into DemoTable values(101, ''); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(102, 'Chris'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable values(103, null); Query OK, 1 ... Read More
The value at the current position of the buffer is read and then incremented using the method get() in the class java.nio.IntBuffer. This method returns the value that is at the current buffer position. Also, the BufferUnderflowException is thrown if underflow situation occurs.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo { public static void main(String[] args) { int n = 5; try { IntBuffer buffer = IntBuffer.allocate(n); buffer.put(8); buffer.put(1); ... Read More
Before getting into an example, we should know what singleton design pattern is. A singleton is a design pattern that restricts the instantiation of a class to only one instance. Notable uses include controlling concurrency and creating a central point of access for an application to access its data store.This example demonstrates How to use Singleton Notification in androidStep 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 ... Read More