IntStream anyMatch Method in Java

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

627 Views

The anyMatch() method in the IntStream class in Java returns whether any elements of this stream match the provided predicate.The syntax is as followsboolean anyMatch(IntPredicate predicate)To work with the IntStream class in Java, import the following packageimport java.util.stream.IntStream;Here, the predicate parameter is a stateless predicate to apply to elements of this stream.Create an IntStream and add some elementsIntStream intStream = IntStream.of(20, 40, 60, 80, 100);Now, use the anyMatch() method to set for a condition. If any of the element match with the condition, TRUE is returnedboolean res = intStream.anyMatch(a -> a < 50); The following is an example to implement ... Read More

DoubleStream generate Method in Java

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

192 Views

The generate() method of the DoubleStream class returns an infinite sequential unordered stream where each element is generated by the provided DoubleSupplier.The syntax is as followsstatic DoubleStream generate(DoubleSupplier s)Here, the parameter s is the DoubleSupplier for generated elements. The DoubleSupplier is a supplier of double-valued results. To use the DoubleStream class in Java, import the following packageimport java.util.stream.DoubleStream;The following is an example to implement DoubleStream generate() method in JavaExample Live Demoimport java.util.*; import java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) {       DoubleStream doubleStream = DoubleStream.generate(()       -> { return (double)(Math.random() * 100); ... Read More

Find Through List of IDs in MongoDB

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

2K+ Views

You can use $in operator to find through the list of ids in MongoDB. 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.findListOfIdsDemo.insertOne({"StudentName":"Carol", "StudentAge":21}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8ecadd2f684a30fbdfd575") } > db.findListOfIdsDemo.insertOne({"StudentName":"Bob", "StudentAge":25}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8ecae42f684a30fbdfd576") } > db.findListOfIdsDemo.insertOne({"StudentName":"David", "StudentAge":22}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8ecaed2f684a30fbdfd577") } > db.findListOfIdsDemo.insertOne({"StudentName":"John", "StudentAge":20}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8ecaf82f684a30fbdfd578") } > db.findListOfIdsDemo.insertOne({"StudentName":"Mike", "StudentAge":23}); {    "acknowledged" : true,    "insertedId" ... Read More

Search a String with Special Characters in a MongoDB Document

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

2K+ Views

To search a string with special characters in MongoDB document, you can use \. Here, we have special character $ in our string.Let us first implement the following query to create a collection with documents>db.searchDocumentWithSpecialCharactersDemo.insertOne({"UserId":"Smith$John123", "UserFirstName":"John", "UserLastName":"Smith"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c987b98330fd0aa0d2fe4b1") } >db.searchDocumentWithSpecialCharactersDemo.insertOne({"UserId":"Taylor$Carol983", "UserFirstName":"Carol", "UserLastName":"Taylor"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c987bdb330fd0aa0d2fe4b2") } >db.searchDocumentWithSpecialCharactersDemo.insertOne({"UserId":"Doe$John999", "UserFirstName":"John", "UserLastName":"Doe"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c987bee330fd0aa0d2fe4b3") } >db.searchDocumentWithSpecialCharactersDemo.insertOne({"UserId":"Miller$David555", "UserFirstName":"David", "UserLastName":"Miller"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c987c01330fd0aa0d2fe4b4") }Following is the query to display all documents from a collection with the help of ... Read More

MySQL Converts BOOL to TINYINT(1) Internally

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

1K+ Views

Yes, MySQL internally convert bool to tinyint(1) because tinyint is the smallest integer data type.You can also say the bool is synonym for tinyint(1). Let us first create a sample table:mysql> create table boolToTinyIntDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(20), -> isAgeGreaterThan18 bool -> ); Query OK, 0 rows affected (1.02 sec)Let us now check the description of table:mysql> desc boolToTinyIntDemo;This will produce the following output+--------------------+-------------+------+-----+---------+----------------+ | Field ... Read More

Remove MySQL Collection Named Group

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

105 Views

The group is a type of method in MongoDB. It shouldn’t be created as a collection name. Even if you created it, you can easily remove it using getCollection('group').drop();). Let us first create a collection with documents −> db.createCollection('group'); { "ok" : 1 } > db.getCollection('group').insertOne({"StudentName":"Chris"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb80fe9623186894665ae3c") } > db.getCollection('group').insertOne({"StudentName":"Robert"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb80fef623186894665ae3d") }Following is the query to display all documents from the collection with the help of find() method −> db.getCollection('group').find().pretty();This will produce the following output −{ "_id" : ObjectId("5cb80fe9623186894665ae3c"), "StudentName" : "Chris" } { ... Read More

Use Prepared Statement for SELECT Query in Java with MySQL

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

8K+ Views

You need to use executeQuery() for this. The syntax is as follows −yourPreparedStatementObject=yourConnectionObject.prepareStatement(yourQueryName); yourresultSetObject=yourPreparedStatementObject.executeQuery();Create a table in the database ‘sample’. The query to create a table is as follows −mysql> create table JavaPreparedStatement -> ( -> Id int, -> Name varchar(10), -> Age int -> ); Query OK, 0 rows affected (0.89 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into JavaPreparedStatement values(1, 'Larry', 23); Query OK, 1 row affected (0.16 sec) mysql> insert into JavaPreparedStatement values(2, ... Read More

8212 Non-Programmable 8-Bit I/O Port

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

803 Views

There are two types of Input Output ports. They are Programmable Input Output ports and Non-Programmable Input Output ports. Since the functions of Programmable Input Output ports changed by software they became more popular. We don’t need to change the wiring rather the hardware of the I/O port to change the function. Intel 8255 is a popular Input Output chip based on port. Whereas the I/O ports which are non-programmable needs to change the wiring or the hardware to change its complete function. We will see in later that the connection needs to be changed when 8212 works like an ... Read More

Create Pair Tuple Using with() Method in Java

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

131 Views

You can also create a Pair Tule in Java using the with() method.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 to create Pair Tuple using with() method −import org.javatuples.Pair; public class Demo {    public static ... Read More

Add Created At Column for Timestamp in MySQL

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

4K+ Views

You need to use ALTER command to add a created at column to an already created table in MySQL.Let us first create a table. The query to create a table is as follows. Here is your table without the “created at” columnmysql> create table formDemo - > ( - > Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, - > Email varchar(128), - > PhoneNumber varchar(15), - > Country varchar(30), - > Platform varchar(40) - > ); Query OK, 0 ... Read More

Advertisements