Chandu yadav has Published 1091 Articles

LongStream findFirst() method in Java

Chandu yadav

Chandu yadav

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

131 Views

The findFirst() method of the LongStream class in Java returns an OptionalLong describing the first element of this stream, or an empty OptionalLong if the stream is empty.The syntax is as follows.OptionalLong findFirst()Here, OptionalLong is a container object which may or may not contain a long value. For OptionalLong, import ... Read More

ArrayBlockingQueue add() method in Java

Chandu yadav

Chandu yadav

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

107 Views

To add elements to the ArrayBlockingQueue class, use the add() method.The syntax is as followsboolean add(E ele)Here, ele is the element to be added to the queue. To work with ArrayBlockingQueue class, you need to import the following packageimport java.util.concurrent.ArrayBlockingQueue;The following is an example to add elements in Java ArrayBlockingQueue classExample Live ... Read More

Only insert if a value is unique in MongoDB else update

Chandu yadav

Chandu yadav

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

768 Views

You can use upsert i.e. whenever you insert a value and it already exist then update would be performed. If the value does not already exist then it would get inserted.Let us first create a collection with documents> db.onlyInsertIfValueIsUniqueDemo.insertOne({"StudentName":"Larry", "StudentAge":22}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9a633815e86fd1496b38a4") } ... Read More

Does MySQL have an expanded output flag similar PostgreSQL?

Chandu yadav

Chandu yadav

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

142 Views

Yes, you can get expanded out in MySQL using the /G, instead of semicolon(;). The syntax is as followsSELECT *FROM yourTableName\GLet us first create a table as an examplemysql> create table expandedOutputDemo    - > (    - > EmployeeId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    - > EmployeeName ... Read More

LongStream mapToInt() method in Java

Chandu yadav

Chandu yadav

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

988 Views

The mapToInt() method returns an IntStream consisting of the results of applying the given function to the elements of this stream.The syntax is as followsmapToInt(LongToIntFunction mapper)Here, the parameter mapper is the stateless function applied to each element.Declare LongStream and add some elementsLongStream longStream = LongStream.of(1000L, 13000L, 18000L);Now, use the IntStream ... Read More

Perform conditional upserts or updates in MongoDB

Chandu yadav

Chandu yadav

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

143 Views

For conditional upserts or updates, you can use $max operator. Let us first create a collection with documents>db.conditionalUpdatesDemo.insertOne({"_id":100, "StudentFirstScore":89, "StudentSecondScore":78, "BiggestScore":89}); { "acknowledged" : true, "insertedId" : 100 } >db.conditionalUpdatesDemo.insertOne({"_id":101, "StudentFirstScore":305, "StudentSecondScore":560, "BiggestScore":1050}); { "acknowledged" : true, "insertedId" : 101 } >db.conditionalUpdatesDemo.insertOne({"_id":103, "StudentFirstScore":560, "StudentSecondScore":789, "BiggestScore":880}); { "acknowledged" : true, "insertedId" ... Read More

ArrayBlockingQueue peek() Method in Java

Chandu yadav

Chandu yadav

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

153 Views

The peek() method of the ArrayBlockingQueue class returns the head of this queue or null if this queue is empty.The syntax is as follows.public E peek()To work with ArrayBlockingQueue class, you need to import the following package.import java.util.concurrent.ArrayBlockingQueue;The following is an example to implement peek() method of Java ArrayBlockingQueue class.Example Live ... Read More

Add to existing value in MySQL column using CONCAT function?

Chandu yadav

Chandu yadav

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

871 Views

To understand the concept, let us first create a demo table.mysql> create table addToExistingValueDemo    -> (    -> Instructor_Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> Instructor_Name varchar(30),    -> Instructor_TechnicalSubject text    -> ); Query OK, 0 rows affected (0.54 sec)Insert some records in the table using ... Read More

Decimal addition in 8085 Microprocessor

Chandu yadav

Chandu yadav

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

2K+ Views

In a digital computer, everything is represented using 0s and 1s only. For example, instruction will have a code using only 0s and 1s. Data is also represented using 0s and 1s. Data can be of different types like unsigned numbers, signed numbers, floating point numbers, binary coded decimal (BCD) ... Read More

Is it possible to sum two fields in MongoDB using the Aggregation framework?

Chandu yadav

Chandu yadav

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

1K+ Views

Yes, it is possible using the $project operator. Let us first create a collection with documents> db.sumTwoFieldsDemo.insertOne({"FirstValue":150, "SecondValue":350}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9b4bfe15e86fd1496b38cd") } > db.sumTwoFieldsDemo.insertOne({"FirstValue":450, "SecondValue":1550}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c9b4c1215e86fd1496b38ce") } > db.sumTwoFieldsDemo.insertOne({"FirstValue":2560, "SecondValue":2440}); {    "acknowledged" : true,   ... Read More

Advertisements