IntStream Average Method in Java

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

11K+ Views

The average() method of the IntStream class in Java returns an OptionalDouble describing the arithmetic mean of elements of this stream, or an empty optional if this stream is empty. It gets the average of the elements of the stream.The syntax is as followsOptionalDouble average()Here, OptionalDouble is a container object which may or may not contain a double value.Create an IntStream with some elementsIntStream intStream = IntStream.of(15, 13, 45, 18, 89, 70, 76, 56);Now, get the average of the elements of the streamOptionalDouble res = intStream.average();The following is an example to implement IntStream average() method in Java. The isPresent() method ... Read More

Perform Ascending Order Sort in MongoDB

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

252 Views

To sort in ascending order, the syntax is as follows −db.yourCollectionName.find().sort({yourField:1});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.sortingDemo.insertOne({"Value":100}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8f8e2ed3c9d04998abf006") } > db.sortingDemo.insertOne({"Value":1}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8f8e31d3c9d04998abf007") } > db.sortingDemo.insertOne({"Value":150}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8f8e34d3c9d04998abf008") } > db.sortingDemo.insertOne({"Value":250}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8f8e37d3c9d04998abf009") } > db.sortingDemo.insertOne({"Value":5}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8f8e3bd3c9d04998abf00a") } > db.sortingDemo.insertOne({"Value":199}); {    "acknowledged" : ... Read More

List All Values of a Certain Field in MongoDB

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

2K+ Views

To get the list of all values of certain fields in MongoDB, you can use distinct(). The syntax is as follows −db.yourCollectionName.distinct( "yourFieldName");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.listAllValuesOfCeratinFieldsDemo.insertOne({"ListOfValues":[10, 20, 30]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8fc89ed3c9d04998abf011") } > db.listAllValuesOfCeratinFieldsDemo.insertOne({"ListOfValues":[40, 50, 60]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8fc8abd3c9d04998abf012") } > db.listAllValuesOfCeratinFieldsDemo.insertOne({"ListOfValues":[10, 20, 30]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8fc8d7d3c9d04998abf013") } > db.listAllValuesOfCeratinFieldsDemo.insertOne({"ListOfValues":[40, 50, 70]}); {    "acknowledged" : true,    "insertedId" ... Read More

Change Datatype of a Column in an Existing Table Using JDBC API

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

886 Views

You can change the datatype of a column in a table using the ALTER TABLE command.SyntaxALTER TABLE Sales MODIFY COLUMN column_name column_new_datatuypeAssume we have a table named Sales in the database with 7 columns namely ProductName, CustomerName, DispatchDate, DeliveryTime, Price, Location and, ID with description as:+--------------+--------------+------+-----+---------+-------+ | Field        | Type         | Null | Key | Default | Extra | +--------------+--------------+------+-----+---------+-------+ | ProductName  | varchar(255) | YES  |     | NULL | | | CustomerName | varchar(255) | YES  |     | NULL ... Read More

RTTI - Run Time Type Information in C++

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

648 Views

In this section we will see what is the RTTI (Runtime Type Information) in C++. In C++ the RTTI is a mechanism, that exposes information about an object’s datatype during runtime. This feature can be available only when the class has at least one virtual function. It allows the type of an object to be determined when the program is executing.In the following example the first code will not work. It will generate an error like “cannot dynamic_cast base_ptr (of type Base*) to type ‘class Derived*’ (Source type is not polymorphic)”. This error comes because there is no virtual function ... Read More

Make Custom Objects Parcelable in Android

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

452 Views

This example demonstrates how can I make my custom objects ParcelableStep 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 code, we have taken button view to show parcel object values.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.view.View; import android.widget.Toast; public class MainActivity extends AppCompatActivity {    parcleObject sample;    @RequiresApi(api = Build.VERSION_CODES.LOLLIPOP)    @Override    protected ... Read More

Check if Location Manager is Running in iOS App

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

423 Views

To check any services related to location in ios with swift we can use the CLLocationManager.In this example we’ll see how to check if the location manager is running or not. We’ll do this with help of an sample project. So, create a new project. First we need to create a locationManager object, so in your view controller.var locationManager = CLLocationManager()Now, we first of all we need to check if the location services are enabled on the device or not. To check this we’ll useCLLocationManager.locationServicesEnabled() function, which returns a Boolean value showing whether the location service on device is active ... Read More

Fetch Records in MongoDB by Querying Its Subset

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

148 Views

You can use $all operator. Let us first create a collection with documents −> db.subsetOfAnArrayDemo.insertOne({"StudentProgrammingSkills":    ["Java", "MongoDB", "MySQL", "C++", "Data Structure", "Algorithm", "Python", "Oracle", "SQL Server"]}); {    "acknowledged" : true,    "insertedId" : ObjectId("5cb9d1e1895c4fd159f80804") }Following is the query to display all documents from the collection with the help of find() method −> db.subsetOfAnArrayDemo.find().pretty();This will produce the following output −{    "_id" : ObjectId("5cb9d1e1895c4fd159f80804"),    "StudentProgrammingSkills" : [       "Java",       "MongoDB",       "MySQL",       "C++",       "Data Structure",       "Algorithm",       "Python",     ... Read More

Insert Special Character Such as Single Quote into MySQL

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

4K+ Views

To insert a special character such as “ ‘ “ (single quote) into MySQL, you need to use \’ escape character. The syntax is as follows −insert into yourTableName(yourColumnName) values(' yourValue\’s ');To understand the above syntax, let us create two tables. The query to create first table is as follows −mysql> create table AvoidInsertErrorDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Sentence text -> ); Query OK, 0 rows affected (0.53 sec)Now you can insert special character such as ‘ in the table using insert command. The query is as follows −mysql> insert into AvoidInsertErrorDemo(Sentence) values('a ... Read More

Contains Method of Pair Class in Java Tuples

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

297 Views

Search a value in a Pair Class using the contains() 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 −Exampleimport org.javatuples.Pair; public class Demo {    public static void main(String[] args) {       Pair < ... Read More

Advertisements