IntStream distinct Method in Java

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

156 Views

The distinct() method in the IntStream class in Java returns a stream consisting of the distinct elements of this stream.The syntax is as followsIntStream distinct()Let’s say we have the following elements in the stream. Some of them are repeatedIntStream intStream = IntStream.of(10, 20, 30, 20, 10, 50, 80, 90, 100, 80);To get the distinct elements, use the IntStream distinct() method.The following is an example to implement IntStream distinct() method in JavaExample Live Demoimport java.util.stream.IntStream; public class Demo {    public static void main(String[] args) {       IntStream intStream = IntStream.of(10, 20, 30, 20, 10, 50, 80, 90, 100, 80); ... Read More

MongoDB Query to Select Records Having a Given Key

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

180 Views

To select records having a given key, you can use $exists operator. The syntax is as follows −db.yourCollectionName.find( { yourFieldName: { $exists : true } } ).pretty();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.selectRecordsHavingKeyDemo.insertOne({"StudentName":"John", "StudentAge":21, "StudentMathMarks":78}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8b7be780f10143d8431e0f") } > db.selectRecordsHavingKeyDemo.insertOne({"StudentName":"Carol", "StudentMathMarks":89}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8b7bfc80f10143d8431e10") } > db.selectRecordsHavingKeyDemo.insertOne({"StudentName":"Sam", "StudentAge":26, "StudentMathMarks":89}); {    "acknowledged" : true,    "insertedId" : ObjectId("5c8b7c1280f10143d8431e11") } > db.selectRecordsHavingKeyDemo.insertOne({"StudentName":"Sam", "StudentMathMarks":98}); {    "acknowledged" : true, ... Read More

Select or Shift to Another Database in MySQL Using JDBC API

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

496 Views

In general, You can change the current database in MySQL using the USE query.SyntaxUse DatabaseName;To change the current database using JDBC API you need to:Register the driver: Register the driver class using the registerDriver() method of the DriverManager class. Pass the driver class name to it, as parameter.Establish a connection: Connect ot the database using the getConnection() method of the DriverManager class. Passing URL (String), username (String), password (String) as parameters to it.Create Statement: Create a Statement object using the createStatement() method of the Connection interface.Execute the Query: Execute the query using the execute() method of the Statement interface.ExampleFollowing JDBC ... Read More

The build() Method in Java Stream Builder

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

5K+ Views

The build() method in Stream.Builder class is used to build the stream. It returns the built stream.The syntax is as follows:Streaml build()Import the following package for the Stream.Builder class in Java:import java.util.stream.Stream;Declare a Stream.Builder:Stream.Builder builder = Stream.builder();Add some elements in the stream:builder.add("One"); builder.add("Two"); builder.add("Three");Now, use the build() method:Stream str = builder.build();The following is an example displaying how to implement build() method of Stream.Builder in Java:Example Live Demoimport java.util.stream.Stream; public class Demo {    public static void main(String[] args) {       Stream.Builder builder = Stream.builder();       builder.add("One");       builder.add("Two");       builder.add("Three");       ... Read More

Use pop() in Android ConcurrentLinkedDeque

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

134 Views

Before getting into an example, we should know what ConcurrentLinkedDeque is, it is unbounded deque based on linked nodes. Multiple threads can access deque elements with safety.This example demonstrates about How to use pop() in android ConcurrentLinkedDequeStep 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 a text view to show ConcurrentLinkedDeque elements.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.os.Build; import android.os.Bundle; ... Read More

Bisect Array Bisection Algorithm in Python

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

694 Views

Performing sort operations after every insertion on a long list may be expensive in terms of time consumed by processor. The bisect module ensures that the list remains automatically sorted after insertion. For this purpose, it uses bisection algorithm. The module has following functions:bisect_left()This method locates insertion point for a given element in the list to maintain sorted order. If it is already present in the list, the insertion point will be before (to the left of) any existing entries. The return value caan be used as the first parameter to list.insert()bisect_right()This method is similar to bisect_left(), but returns an ... Read More

Get the Reverse of a NavigableSet in Java

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

115 Views

We will create a NavigableSet collection and add some elements −NavigableSet set = new TreeSet(); set.add("ABC"); set.add("DEF"); set.add("GHI"); set.add("JKL"); set.add("MNO"); set.add("PQR"); set.add("STU");Now, use descendingSet() for the reverse of NavigableSet −NavigableSetreverse = set.descendingSet();Example Live Demoimport java.util.NavigableSet; import java.util.TreeSet; public class Demo {    public static void main(String[] args) {       NavigableSet set = new TreeSet();       set.add("ABC");       set.add("DEF");       set.add("GHI");       set.add("JKL");       set.add("MNO");       set.add("PQR");       set.add("STU");       NavigableSetreverse = set.descendingSet();       System.out.println("NavigableSet = " + set);       ... Read More

Interfacing 7 Segment Display to 8085 Microprocessor

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

15K+ Views

 An output device which is very common is, especially in the kit of 8085 microprocessor and it is the Light Emitting Diode consisting of seven segments. Moreover, we have eight segments in a LED display consisting of 7 segments which includes ‘.’, consisting of character 8 and having a decimal point just next to it. We denote the segments as ‘a, b, c, d, e, f, g, and dp’ where dp signifies ‘.’ which is the decimal point. Moreover, these are LEDs or together a series of Light Emitting Diodes. We have shown the internal circuit comprising of a display ... Read More

Get Android Application Version Name

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

3K+ Views

This example demonstrate about How to get android application version name.Step 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 text view to show application version name.Step 3 − Add the following code to src/MainActivity.javapackage com.example.myapplication; import android.app.ActivityManager; import android.content.Context; import android.content.pm.PackageInfo; import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; import android.support.annotation.RequiresApi; import android.support.v7.app.AppCompatActivity; import android.telephony.TelephonyManager; import android.view.WindowManager; import android.widget.TextView; import java.util.List; public class MainActivity extends ... Read More

Important Methods of the SQLException Class

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

322 Views

An SQLException can occur both in the driver and the database. When such an exception occurs, an object of type SQLException will be passed to the catch clause.The passed SQLException object has the following methods available for retrieving additional information about the exception:MethodDescriptiongetErrorCode( )Gets the error number associated with the exception.getMessage( )Gets the JDBC driver's error message for an error, handled by the driver or gets the Oracle error number and message for a database error.getSQLState( )Gets the XOPEN SQLstate string. For a JDBC driver error, no useful information is returned from this method. For a database error, the five-digit ... Read More

Advertisements