The setAt0() method is used to set the Pair value in JavaTuples and a copy with a new value at the specified index i.e. index 1 here.Let us first see what we need to work with JavaTuples. To work with Pair class in JavaTuples, you need to import the following package −import org.javatuples.Pair;Note − Steps to download and run JavaTuples program If you are using Eclipse IDE to run Pair Class in JavaTuples, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file.The following is an example −Exampleimport org.javatuples.Pair; ... Read More
This example demonstrates How to remove data from tree set 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 have taken the name and record number as Edit text, when the user clicks on save button it will store the data into ArrayList. Click on delete ... Read More
HTTP is a "stateless" protocol which means each time a client retrieves a Webpage, the client opens a separate connection to the Web server and the server automatically does not keep any record of previous client request.Maintaining Session Between Web Client And ServerLet us now discuss a few options to maintain the session between the Web Client and the Web Server −CookiesA webserver can assign a unique session ID as a cookie to each web client and for subsequent requests from the client they can be recognized using the received cookie.This may not be an effective way as the browser ... Read More
This example demonstrate about How to use startsWith () 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. 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; public class MainActivity extends AppCompatActivity { EditText name; Button button; TextView text; @Override protected void onCreate(Bundle savedInstanceState) { ... Read More
To search for a value in KeyValue Tuple, use the contains() method. Here, the value to be searched should be set as the parameter of the method. The return value is a boolean i.e. TRUE, if the value exists, else FALSE. Let us first see what we need to work with JavaTuples. To work with KeyValue class in JavaTuples, you need to import the following packageimport org.javatuples.KeyValue;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 ... Read More
In order to replace substring in MongoDB document, you can use the replace() function. To understand it further, let us create a collection with document. The query to create a collection with document is as follows −> db.replaceSubstringDemo.insertOne({"WebsiteURL":"www.gogle.com"}); { "acknowledged" : true, "insertedId" : ObjectId("5c76eaf21e9c5dd6f1f78276") }Display all documents from a collection with the help of find() method. The query is as follows −> db.replaceSubstringDemo.find().pretty();Output{ "_id" : ObjectId("5c76eaf21e9c5dd6f1f78276"), "WebsiteURL" : "www.gogle.com" }Here is the query to replace substring in MongoDB document −> db.replaceSubstringDemo.find({WebsiteURL:"www.gogle.com"}).forEach(function(url, k){ ... url.WebsiteURL=url.WebsiteURL.replace("www.gogle.com", "www.google.com"); ... db.replaceSubstringDemo.save(url) ... });Let us display the ... Read More
You can use distinct() to return only unique values. The syntax is as follows −db.yourCollectionName.distinct("yourFieldName");To understand the concept, let us create a collection with the document. The query to create a collection with a document is as follows −> db.returnOnlyUniqueValuesDemo.insertOne({"CusomerName":"Larry", "CustomerAge":23}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ed7262f684a30fbdfd580") } > db.returnOnlyUniqueValuesDemo.insertOne({"CusomerName":"Mike", "CustomerAge":21}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ed72d2f684a30fbdfd581") } > db.returnOnlyUniqueValuesDemo.insertOne({"CusomerName":"Sam", "CustomerAge":21}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ed7322f684a30fbdfd582") } > db.returnOnlyUniqueValuesDemo.insertOne({"CusomerName":"Carol", "CustomerAge":25}); { "acknowledged" : true, "insertedId" : ObjectId("5c8ed73a2f684a30fbdfd583") } > db.returnOnlyUniqueValuesDemo.insertOne({"CusomerName":"David", "CustomerAge":22}); { "acknowledged" : true, "insertedId" ... Read More
Yes, you can get the first item in a cursor object using findOne() method. Following is the syntaxdb.yourCollectionName.findOne();However, the following syntax is used if you want a single document in a cursor objectdb.yourCollectionName.findOne({yourCondition});We will first create a collection. Following is the query to create a collection with documents> db.getFirstItemDemo.insertOne({"CustomerName":"Chris", "CustomerAge":28}); { "acknowledged" : true, "insertedId" : ObjectId("5c989059330fd0aa0d2fe4c1") } > db.getFirstItemDemo.insertOne({"CustomerName":"Larry", "CustomerAge":26}); { "acknowledged" : true, "insertedId" : ObjectId("5c989063330fd0aa0d2fe4c2") } > db.getFirstItemDemo.insertOne({"CustomerName":"Robert", "CustomerAge":29}); { "acknowledged" : true, "insertedId" : ObjectId("5c98906d330fd0aa0d2fe4c3") } > db.getFirstItemDemo.insertOne({"CustomerName":"David", "CustomerAge":39}); { "acknowledged" : true, "insertedId" : ObjectId("5c989081330fd0aa0d2fe4c4") }Following is ... Read More
Set the same condition like “OR” in a MySQL CASE expression. Let us first create a sample table.Following is the querymysql> create table caseOrConditionDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(100), -> Score int -> ); Query OK, 0 rows affected (0.49 sec)Following is the query to insert some records in the table using insert command:mysql> insert into caseOrConditionDemo(Name, Score) values('Larry', 85); Query OK, 1 row affected (0.18 sec) mysql> insert into caseOrConditionDemo(Name, Score) values('Sam', 74); Query OK, 1 row affected (0.20 sec) mysql> insert into caseOrConditionDemo(Name, ... Read More
The findOne() returns first document if query matches otherwise returns null. The find() method does not return null, it returns a cursor.Let us implement the concept of find() and findOne() and create a collection with documents −> db.createCollection('emptyCollection'); { "ok" : 1 }Let us count how many documents are in the above collection −> db.emptyCollection.count();This will produce the following output −0There is no document present in the above collection.Following is the query to check the result with findOne() −> if(db.emptyCollection.findOne()){print("Returns Cursor")} else {print("Not returning cursor")} This will produce the following output −Not returning cursorFollowing is the query to check the ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP