LongStream mapToDouble Method in Java

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

164 Views

The mapToDouble() method returns a DoubleStream consisting of the results of applying the given function to the elements of this stream.The syntax is as follows:DoubleStream mapToDouble(LongToDoubleFunction mapper)The parameter mapper is a stateless function to apply to each element.To use the LongStream class in Java, import the following package:import java.util.stream.LongStream;The following is an example to implement LongStream mapToDouble() method in JavaExampleimport java.util.stream.LongStream; import java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args) {       LongStream longStream = LongStream.of(5000L, 12000L, 15000L, 20000L, 25000L);       DoubleStream s = longStream.mapToDouble(a → (double)a);       System.out.println("Elements of DoubleStream..."); ... Read More

Get Highest Value of a Column in MongoDB

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

1K+ Views

To get the highest value of a column in MongoDB, you can use sort() along with limit(1). The syntax is as follows −db.yourCollectionName.find().sort({"yourFieldName":-1}).limit(1);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.gettingHighestValueDemo.insertOne({"Value":1029}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c900b885705caea966c5574") } > db.gettingHighestValueDemo.insertOne({"Value":3029}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c900b8d5705caea966c5575") } > db.gettingHighestValueDemo.insertOne({"Value":1092}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c900b925705caea966c5576") } > db.gettingHighestValueDemo.insertOne({"Value":18484}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c900b955705caea966c5577") } > db.gettingHighestValueDemo.insertOne({"Value":37474}); {    "acknowledged" ... Read More

Delete Column from Existing Table in Database using JDBC API

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

787 Views

You can delete a column in a table using the ALTER TABLE command.SyntaxALTER TABLE table_name DROP COLUMN column_name;Assume we have a table named Sales in the database with 7 columns namely id, CustomerName, DispatchDate, DeliveryTime, Price and, Location as shown below:+----+-------------+--------------+--------------+--------------+-------+----------------+ | id | productname | CustomerName | DispatchDate | DeliveryTime | Price | Location     | +----+-------------+--------------+--------------+--------------+-------+----------------+ | 1  | Key-Board   | Raja         | 2019-09-01   | 08:51:36     | 7000  | Hyderabad      | | 2  | Earphones   | Roja         | 2019-05-01   ... Read More

Get All MongoDB Documents Excluding Two Given Criteria

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

115 Views

To get all the MongoDB documents with some given criteria’s, following any of the below given casesCase 1 Following is the query to get all the documents without a single criterion using $ne operatordb.yourCollectionName.find({yourFieldName:{$ne:"yourValue"}}).pretty();Case 2 Following is the query to get all the documents without two given criterions using $nin operatordb.yourCollectionName.find({yourFieldName:{$nin:["yourValue1", "yourValue2"]}}).pretty();Let us first create a collection. Following is the query to create a collection with documents>db.findAllExceptFromOneOrtwoDemo.insertOne({"StudentName":"Larry", "StudentSubjectName":"Java"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c993d82330fd0aa0d2fe4d2") } >db.findAllExceptFromOneOrtwoDemo.insertOne({"StudentName":"Chris", "StudentSubjectName":"C++"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c993d8f330fd0aa0d2fe4d3") } >db.findAllExceptFromOneOrtwoDemo.insertOne({"StudentName":"Robert", "StudentSubjectName":"C"}); { "acknowledged" : true, "insertedId" : ObjectId("5c993d99330fd0aa0d2fe4d4") } ... Read More

Resize UIImageView Using Swift

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

3K+ Views

To resize an image in iOS using swift we’ll make use of frame.Let’s see this with help of an example.Create an empty project and add an empty Image view.Create its outlet.Add an image to your project and assign the image to image view.Initially when we run the application, it looks something like this.Now, let’s add code to resize the image.override func viewWillLayoutSubviews() {    let frame = CGRect(x: 10, y: 10, width: self.view.frame.width - 20, height: 300)    self.imgView.frame = frame }We will run this code in our viewWillLayoutSubviews method. This is how it looks on the device when we ... Read More

Check Weakly or Strongly Connected Graph in C++

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

288 Views

Weakly or Strongly Connected for a given a directed graph can be find out using DFS. This is a C++ program of this problem.Functions usedBegin    Function fillorder() = fill stack with all the vertices.    a) Mark the current node as visited and print it    b) Recur for all the vertices adjacent to this vertex    c) All vertices reachable from v are processed by now, push v to Stack End Begin    Function DFS() :    a) Mark the current node as visited and print it    b) Recur for all the vertices adjacent to this vertex ... Read More

Delete a Field and Value in MongoDB

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

446 Views

To delete a MongoDB field and value, you can use $unset operator. Let us first create a collection with documents −> db.deleteFieldDemo.insertOne({"FirstName":"John", "LastName":"Smith"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb9fb767219729fde21ddad") } > db.deleteFieldDemo.insertOne({"FirstName":"David", "LastName":"Miller"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb9fb837219729fde21ddae") } > db.deleteFieldDemo.insertOne({"FirstName":"Carol", "LastName":"Taylor"}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb9fb8d7219729fde21ddaf") }Following is the query to display all documents from the collection with the help of find() method −> db.deleteFieldDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cb9fb767219729fde21ddad"),    "FirstName" : "John",    "LastName" : "Smith" } {    "_id" : ... Read More

Using TIME Data Type in MySQL Without Seconds

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

2K+ Views

You need to use DATE_FORMAT() for this. The syntax is as follows −SELECT DATE_FORMAT(yourColumnName, '%k:%i') as anyAliasName FROM yourTableName;You can use ‘%H:%i’ for the same result. To understand the above syntax, let us create a table.The query to create a table is as follows −mysql> create table TimeDemo    -> (    -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY,    -> LastLoginTime time    -> ); Query OK, 0 rows affected (0.56 sec)Now you can insert some records in the table using insert command. The query is as follows −mysql> insert into TimeDemo(LastLoginTime) values('09:30:35'); Query OK, 1 row affected ... Read More

Duration ofSeconds Method in Java

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

1K+ Views

The duration can be obtained in a one second format using the ofSeconds() method in the Duration class in Java. This method requires two parameters i.e. the number of seconds and the adjustment required in nanoseconds. Also, it returns the duration in a one second format. If the capacity of the duration is exceeded, then the ArithmeticException is thrown.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo {    public static void main(String[] args) {       long seconds = 515793;     long adjustment = 100; ... Read More

Iterate Through Java Pair Tuple

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

2K+ Views

The iteration through Pair in JavaTuples is the same as you may have seen in Java Arrays collection.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; public class Demo {    public static void main(String[] ... Read More

Advertisements