IntStream generate Method in Java

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

561 Views

The generate() method in the IntStream class returns an infinite sequential unordered stream where each element is generated by the provided IntSupplier.The syntax is as followsstatic IntStream generate(IntSupplier i)Here, i is the IntSupplier for generated elements. The IntSupplier represents a supplier of int-valued results.The following is an example to implement IntStream generate() method in Java. We have used the limit() method here as well to limit the number of elements we want from the streamExample Live Demoimport java.util.*; import java.util.stream.IntStream; public class Demo {    public static void main(String[] args) {       IntStream intStream = IntStream.generate(()       ... Read More

Check if Field Exists with MongoDB

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

220 Views

You can use the $exists and $ne operator for this. To understand the concept further, let us create a collection with document. The query to create a collection with document is as follows −> db.checkFieldExistDemo.insertOne({"EmployeeId":1, "EmployeeName":"John", "isMarried":true, "EmployeeSalary":4648585}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c76f7b31e9c5dd6f1f78281") } > db.checkFieldExistDemo.insertOne({"StudentId":2, "StudentName":"John", "isMarried":false, " StudentAge":19}); {    "acknowledged" : true, 0    "insertedId" : ObjectId("5c76f7e11e9c5dd6f1f78282") }Display all documents from a collection with the help of find() method. The query is as follows −> db.checkFieldExistDemo.find().pretty();Output{    "_id" : ObjectId("5c76f7b31e9c5dd6f1f78281"),    "EmployeeId" : 1,    "EmployeeName" : "John",    "isMarried" : true,   ... Read More

Opposite of addToSet to removeFromSet in MongoDB

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

1K+ Views

To get the opposite of $addToSet to '$removeFromSet', use the $pull operator.Let us create a collection with a document. The query to create a collection with a document is as follows −> db.oppositeAddToSetDemo.insertOne({"StudentName":"John", "StudentHobby":["Cricket", "Cooking", "Drawing"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8eddcc2f684a30fbdfd588") } > db.oppositeAddToSetDemo.insertOne({"StudentName":"Carol", "StudentHobby":["Cricket", "Dance", "Hiking"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8eddfd2f684a30fbdfd589") } > db.oppositeAddToSetDemo.insertOne({"StudentName":"David", "StudentHobby":["Learning", "Photography"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8ede272f684a30fbdfd58a") }Display all documents from a collection with the help of find() method. The query is as follows −> db.oppositeAddToSetDemo.find().pretty();The following is the output −{    "_id" ... Read More

Get All Collections from All MongoDB Databases

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

549 Views

To get all the collections from all the databases, let us first get all the databases using the following query> switchDatabaseAdmin = db.getSiblingDB("admin"); admin > allDatabaseName = switchDatabaseAdmin.runCommand({ "listDatabases": 1 }).databases;This will produce the following output[    {       "name" : "admin",       "sizeOnDisk" : 495616,       "empty" : false    },    {       "name" : "config",       "sizeOnDisk" : 98304,       "empty" : false    },    {       "name" : "local",       "sizeOnDisk" : 73728,       "empty" : false ... Read More

Work with Array Variable in MySQL

Rama Giri
Updated on 30-Jul-2019 22:30:25

2K+ Views

MySQL does not support array variables. To get the same result, use the table DUAL. Following is the syntax:SELECT yourValue1 AS ArrayValue FROM DUAL UNION ALL SELECT yourValue2 FROM DUAL UNION ALL SELECT yourValue3 FROM DUAL UNION ALL SELECT yourValue4 FROM DUAL UNION ALL . . . . . . SELECT yourValueN FROM DUAL;Let us create a sample table:mysql> SELECT 1 AS ArrayValue FROM DUAL       UNION ALL       SELECT 2 FROM DUAL       UNION ALL       SELECT 3 FROM DUAL       UNION ALL       SELECT 4 FROM ... Read More

Creating Alias in a MongoDB Query

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

4K+ Views

You can use aggregate framework to create an alias. Let us first create a collection with documents −> db.creatingAliasDemo.insertOne({_id:101, "Name":"John Doe"}); { "acknowledged" : true, "insertedId" : 101 } > db.creatingAliasDemo.insertOne({_id:102, "Name":"David Miller"}); { "acknowledged" : true, "insertedId" : 102 } > db.creatingAliasDemo.insertOne({_id:103, "Name":"Sam Williams"}); { "acknowledged" : true, "insertedId" : 103 }Following is the query to display all documents from the collection with the help of find() method −> db.creatingAliasDemo.find().pretty();This will produce the following output −{ "_id" : 101, "Name" : "John Doe" } { "_id" : 102, "Name" : "David Miller" } { "_id" : 103, "Name" : ... Read More

Disable SSL Connection Warning in MySQL with Java

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

13K+ Views

To disable the warning while connecting to a database in Java, use the below concept −autoReconnect=true&useSSL=falseThe complete syntax is as follows −yourJdbcURL="jdbc:mysql://localhost:yourPortNumber/yourDatabaseName?autoReconnect=true&useSSL=false";Here is the warning message if you do not include “useSSL=false” −Wed Feb 06 18:53:39 IST 2019 WARN: Establishing SSL connection without server's identity verification is not recommended. According to MySQL 5.5.45+, 5.6.26+ and 5.7.6+ requirements SSL connection must be established by default if explicit option isn't set. For compliance with existing applications not using SSL the verifyServerCertificate property is set to 'false'. You need either to explicitly disable SSL by setting useSSL=false, or set useSSL=true and provide truststore ... Read More

Java 8 Clock hashCode Method

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

271 Views

The hash code for a clock object can be obtained using the method hashCode() in the Clock Class in Java. This method requires no parameters and it returns the acceptable hash code for a clock object.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(); int hashCode = c.hashCode(); System.out.println("The clock is: " + c); System.out.println("The hash ... Read More

SetAt0 Method for Quintet Class in JavaTuples

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

103 Views

The setAt0() method is used to set the Quintet value in JavaTuples and a copy with a new value at the specified index i.e. index 0 here.Let us first see what we need to work with JavaTuples. To work with Quintet class in JavaTuples, you need to import the following package −import org.javatuples.Quintet;Note − Steps to download and run JavaTuples program If you are using Eclipse IDE to run Quintet 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.Quintet; ... Read More

Increment All Rows of a Column by 1 in MySQL Query

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

2K+ Views

To increment all the rows of a particular ID column by 1, you need to use UPDATE command and update the table. The syntax of the query is as follows. We have also used ORDER BY hereUPDATE yourTableName SET yourIdColumnName=yourIdColumnName+1 ORDER BY yourIdColumnName DESC;To understand the above syntax, let us create a table. The query to create a table is as followsmysql> create table IdColumnadd1Demo - > ( - > Id int NOT NULL AUTO_INCREMENT PRIMARY KEY - > ); Query OK, 0 rows affected (0.58 sec)Insert some records in the ... Read More

Advertisements