Use lastIndexOf in Android TextView

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

338 Views

This example demonstrate about How to use lastIndexOf () in Android textview.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 name as Edit text, when user click on button it will take data and returns last index of “sai”.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.os.Bundle; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Button; import android.widget.EditText; import android.widget.TextView; ... Read More

IntStream noneMatch Method in Java

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

745 Views

The noneMatch() method in Java returns whether no elements of this stream match the provided predicate. The true boolean value is returned if either no elements of the stream match the provided predicate or the stream is empty.The syntax is as followsBoolean noneMatch(IntPredicate predicate)Here, parameter predicate is the stateless predicate to apply to elements of this streamCreate an IntStreamIntStream intStream = IntStream.of(15, 25, 50, 60, 80, 100, 130, 150);Here, set a condition that returns whether no elements of this stream match the provided predicate. We are checking for none of the value less than 10boolean res = intStream.noneMatch(a -> a ... Read More

AddAtX Method of the Octet Tuple in Java

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

104 Views

The addAtX() method is used in Octet Tuple to add value. Here, X is the index wherein you need to add the value i.e. to add value at index 0, use the addAt0() and value as a parameter. Let us first see what we need to work with JavaTuples. To work with Octet class in JavaTuples, you need to import the following packageimport org.javatuples.Octet;Note − Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project -> Properties -> Java Build Path -> Add External Jars and upload the downloaded JavaTuples jar file. ... Read More

Increment Value in MongoDB Nested Object

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

495 Views

To increment a value in nested object, you can use $inc operator. Let us first implement the following query to create a collection with documents>db.incrementValueDemo.insertOne({"StudentName":"Larry", "StudentCountryName":"US", "StudentDetails":[{"StudentSubjectName":"Math", "StudentMathMarks":79}]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c986ca0330fd0aa0d2fe4a2") }Following is the query to display all documents from a collection with the help of find() method> db.incrementValueDemo.find().pretty();This will produce the following output{    "_id" : ObjectId("5c986ca0330fd0aa0d2fe4a2"),    "StudentName" : "Larry",    "StudentCountryName" : "US",    "StudentDetails" : [       {          "StudentSubjectName" : "Math",          "StudentMathMarks" : 79       }    ] ... Read More

Count Value for Multiple Columns in MySQL

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

601 Views

To count value for multiple columns, use the CASE statement. Let us first create a table::mysql> create table countValueMultipleColumnsDemo    -> (    -> Value1 int,    -> Value2 int,    -> Value3 int    -> ); Query OK, 0 rows affected (0.62 sec)Following is the query to insert some records in the table using insert command:mysql> insert into countValueMultipleColumnsDemo values(10, 15, 10); Query OK, 1 row affected (0.15 sec) mysql> insert into countValueMultipleColumnsDemo values(20, 30, 10); Query OK, 1 row affected (0.14 sec) mysql> insert into countValueMultipleColumnsDemo values(40, 10, 60); Query OK, 1 row affected (0.18 sec)Following ... Read More

Check if an Undirected Graph is a Tree Using DFS in C++

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

242 Views

A graph is a tree if it does not contain any cycle. This is a C++ program to check whether an undirected graph is tree or not.AlgorithmBegin function cyclicUtil() :    A) Mark the current node as visited.    B) Recur for all the vertices adjacent to this vertex.    C) If an adjacent is not visited, then recur for that adjacent.    D) If an adjacent is visited and not parent of current vertex, then there is a cycle. End Begin function cyclic():    A) Mark all the vertices as not visited and not part of recursion stack.   ... Read More

Apply Condition Only If Field Exists in MongoDB

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

2K+ Views

You can use $or operator for this. Let us first create a collection with documents −> db.applyConditionDemo.insertOne({"StudentName":"Larry", "StudentAge":21, "StudentMarks":45}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb80b78623186894665ae36") } > db.applyConditionDemo.insertOne({"StudentName":"Sam", "StudentAge":23, "StudentMarks":55}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb80b87623186894665ae37") } > db.applyConditionDemo.insertOne({"StudentName":"David", "StudentAge":21, "StudentMarks":65}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb80b95623186894665ae38") } > db.applyConditionDemo.insertOne({"StudentName":"Carol", "StudentAge":24, "StudentMarks":78}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb80ba3623186894665ae39") } > db.applyConditionDemo.insertOne({"StudentName":"Chris", "StudentAge":21, "StudentMarks":88}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb80bae623186894665ae3a") } > db.applyConditionDemo.insertOne({"StudentName":"Robert", "StudentMarks":98}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb80c3d623186894665ae3b") }Following is the ... Read More

Format Date in MySQL Select Query Using FORMATDate Method

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

120 Views

Use the DATE_FORMAT(), not FORMATDATE() in MySQL to format date. The correct syntax is as follows −SE LECT *, DATE_FORMAT(yourDateCoumnName, ’yourFormat’) as anyAliasName FROM yourTableNameTo understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table DateFormatDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> UserName varchar(10),    -> UserLoginDate date    -> ); Query OK, 0 rows affected (0.94 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into DateFormatDemo(UserName, UserLoginDate) values('Mike', curdate()); Query OK, 1 ... Read More

Clock systemDefaultZone Method in Java

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

152 Views

The current instance of the clock with the default time zone can be obtained using the method systemDefaultZone() in the Clock Class in Java. This method requires no parameters and it returns the current instance of the clock with the default time zone.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; public class Demo { public static void main(String[] args) { Clock c = Clock.systemDefaultZone(); Instant i = c.instant(); ZonedDateTime zdt = i.atZone(c.getZone()); ... Read More

Use Random in Android SQLite

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

475 Views

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 random () in Android sqliteStep 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to ... Read More

Advertisements