Create Label-Value Tuple from a List Collection in Java

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

114 Views

To create LabelValue tuple from a List collection, use the fromCollection() method. Here, we will be creating LabelValue from List, therefore use the fromCollection() method.Let us first see what we need to work with JavaTuples. To work with LabelValue class in JavaTuples, you need to import the following package −import org.javatuples.LabelValue;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. Refer the below guide for all the steps to run JavaTuples −Steps − ... Read More

Removing ID Element from PyMongo Results

Smita Kapse
Updated on 30-Jul-2019 22:30:25

638 Views

To remove the _id element, you can use the following syntax −db.yourCollectionName.find({}, {'_id': false}).pretty();To understand the above syntax, let us create a collection with the document. The query to create a collection with a document is as follows −> db.removingidElementDemo.insertOne({"UserName":"John", ... "UserAge":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9153fd4afe5c1d2279d6ad") } > db.removingidElementDemo.insertOne({"UserName":"Carol", "UserAge":24}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9154084afe5c1d2279d6ae") } > db.removingidElementDemo.insertOne({"UserName":"David", "UserAge":22}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9154154afe5c1d2279d6af") } > db.removingidElementDemo.insertOne({"UserName":"Mike", "UserAge":26}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9154204afe5c1d2279d6b0") } > db.removingidElementDemo.insertOne({"UserName":"Chris", "UserAge":20}); {    "acknowledged" : true,   ... Read More

What is Linkify TextView in Android

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

1K+ Views

Before getting into the example we should know, what is linkify. Linkify is just like a Hyper link in HTML. Using that we can browse the content. Here is the simple solution to use linkify with textview 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 XML, we have given a textview, textview contains text and web url link.Step 3 − Add the following code to src/MainActivity.javaimport android.os.Bundle; ... Read More

Get Component of Date from ISODate in MongoDB

Chandu yadav
Updated on 30-Jul-2019 22:30:25

242 Views

To get component of Date/ISODate in MongoDB, let us create a document with date in the collection. Now let us get the component of Date/ISODate in MongoDB> db.componentOfDateDemo.insert({"ShippingDate":new Date()}); WriteResult({ "nInserted" : 1 })Following is the query to display all documents from a collection with the help of find() method> db.componentOfDateDemo.find().pretty()This will produce the following output{    "_id" : ObjectId("5c9e9d57d628fa4220163b68"),    "ShippingDate" : ISODate("2019-03-29T22:33:59.776Z") }Following is the query to get result using findOne()> var result=db.componentOfDateDemo.findOne();Now you can display documents from the collection. Following is the query> resultThis will produce the following output{    "_id" : ObjectId("5c9e9d57d628fa4220163b68"),    "ShippingDate" : ISODate("2019-03-29T22:33:59.776Z") ... Read More

Change File Attribute to Writable in Java

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

142 Views

Let’s say our file is “input.txt”, which is set read-only −File myFile = new File("input.txt"); myFile.createNewFile(); myFile.setReadOnly();Now, set the above file to writable −myFile.setWritable(true);After that, you can use canWrite() to check whether the file is writable or not.Example Live Demoimport java.io.File; public class Demo {    public static void main(String[] args) throws Exception {       File myFile = new File("input.txt");       myFile.createNewFile();       myFile.setReadOnly();       if (myFile.canWrite()) {          System.out.println("Writable!");       } else {          System.out.println("Read only mode!");       }       ... Read More

Count Unique Rows in a MySQL Column

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

220 Views

In MySQL, COUNT() will display the number of rows. DISTINCT is used to ignore duplicate rows and get the count of only unique rows.Let us first create a table:mysql> create table DemoTable (    Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    FirstName varchar(10) ); Query OK, 0 rows affected (0.47 sec)Following is the query to insert some records in the table using insert command:mysql> insert into DemoTable(FirstName) values('Larry'); Query OK, 1 row affected (0.18 sec) mysql> insert into DemoTable(FirstName) values('John'); Query OK, 1 row affected (0.16 sec) mysql> insert into DemoTable(FirstName) values('Sam'); Query OK, 1 row affected (0.13 sec) ... Read More

Mark File or Directory as Read-Only in Java

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

958 Views

A file can be set to read-only by using the method java.io.File.setReadOnly(). This method requires no parameters and it returns true if the file is set to read-only and false otherwise. The method java.io.File.canWrite() is used to check whether the file can be written to in Java and if not, then the file is confirmed to be read-only.A program that demonstrates this is given as follows −Example Live Demoimport java.io.File; public class Demo {    public static void main(String[] args) {       boolean flag;       try {          File file = new File("demo1.txt");   ... Read More

CharBuffer put Method in Java

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

127 Views

The required value can be written at the current position of the buffer and then the current position is incremented using the method put() in the class java.nio.CharBuffer. This method requires a single parameter i.e. the value to be written in the buffer and it returns the buffer in which the value is inserted.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 {          CharBuffer buffer = CharBuffer.allocate(5);     ... Read More

Difference Between Assignment Operator and Copy Constructor in C++

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

733 Views

The Copy constructor and the assignment operators are used to initialize one object to another object. The main difference between them is that the copy constructor creates a separate memory block for the new object. But the assignment operator does not make new memory space. It uses reference variable to point to the previous memory block.Copy Constructor (Syntax)classname (const classname &obj) { // body of constructor }Assignment Operator (Syntax)classname Ob1, Ob2; Ob2 = Ob1;Let us see the detailed differences between Copy constructor and Assignment Operator.Copy ConstructorAssignment OperatorThe Copy constructor is basically an overloaded constructorAssignment operator is basically ... Read More

Remove Array Element in MongoDB

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

839 Views

To remove array element in MongoDB, you can use $pull and $in operator. The syntax is as follows:db.yourCollectionName.update({},    {$pull:{yourFirstArrayName:{$in:["yourValue"]}, yourSecondArrayName:"yourValue"}},    {multi:true} );To understand the above syntax, let us create a collection with document. The query to create a collection with document is as follows:>db.removeArrayElement.insertOne({"StudentName":"Larry", "StudentCoreSubject":["MongoD B", "MySQL", "SQL Server", "Java"], "StudentFavouriteTeacher":["John", "Marry", "Carol"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c6ec9c46fd07954a4890688") }Display all documents from a collection with the help of find() method. The query is as follows:> db.removeArrayElement.find().pretty();The following is the output:{    "_id" : ObjectId("5c6ec9c46fd07954a4890688"),    "StudentName" : "Larry",    "StudentCoreSubject" : [     ... Read More

Advertisements