Instant isSupported Method in Java

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

183 Views

It can be checked if a ChronoUnit is supported by the Instant class or not by using the isSupported() method in the Instant class in Java. This method requires a single parameter i.e. the ChronoUnit to check. It returns true if the ChronoUnit is supported by the Instant class and false otherwise.A program that demonstrates this is given as follows −Example Live Demoimport java.time.*; import java.time.temporal.ChronoUnit; public class Demo {    public static void main(String[] args) {       Instant i = Instant.now();       System.out.println("The current instant is: " + i);       boolean flag = i.isSupported(ChronoUnit.SECONDS); ... Read More

StringJoiner Add Method in Java 8

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

248 Views

The add() method of the StringJoiner class is used in Java 8 to add a copy of the given CharSequence value as the next element of the StringJoiner value. If the new element ele is null, then the value null gets added.The syntax is as follows −public StringJoiner add(CharSequence ele)Here, the parameter ele is the element to be added, whereas, CharSequence is a readable sequence of char values.To work with the StringJoiner in Java 8, import the following package −import java.util.StringJoiner;We will first create a StringJoiner and set the delimeter −StringJoiner strJoin = new StringJoiner(", ")Use the add() method to ... Read More

Iterate Over All MongoDB Databases

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

423 Views

To iterate over all MongoDB databases, you need to switch your database to admin. Following is the query to switch to admin and get information about all the databases> 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    },    {       "name" : "sample",       "sizeOnDisk" : 1335296,       "empty" : false    },    {       "name" : "sampleDemo",       "sizeOnDisk" : 278528,       "empty" : false    },    {       "name" : "studentSearch",       "sizeOnDisk" : 262144,       "empty" : false    },    {       "name" : "test",       "sizeOnDisk" : 8724480,       "empty" : false    } ]

C++ Program to Perform Edge Coloring on Complete Graph

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

387 Views

A complete graph is a graph which has a connecting edge between any pair of vertices. This is a C++ Program to Perform Edge Coloring on Complete Graph.AlgorithmBegin    Take the input of the number of vertices ‘n’.    Construct a complete graph using e=n*(n-1)/2 edges, in ed[][].    Function EdgeColor() is used to Color the graph edges.    A) Assign color to current edge as c i.e. 1 initially.    B) If the same color is occupied by any of the adjacent edges, then       discard this color and go to flag again and try next color. ... Read More

Find Strongly Connected Components in Graphs using C++

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

742 Views

Weakly or Strongly Connected for a given a directed graph can be found 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 EndExample#include ... Read More

ByteBuffer compareTo Method in Java

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

200 Views

A buffer can be compared with another buffer using the method compareTo() in the class java.nio.ByteBuffer. This method returns a negative integer if the buffer is less than the given buffer, zero if the buffer is equal to the given buffer and a positive integer if the buffer is greater than the given buffer.A program that demonstrates this is given as follows −Example Live Demoimport java.nio.*; import java.util.*; public class Demo {    public static void main(String[] args) {       int n = 5;       try {          ByteBuffer buffer1 = ByteBuffer.allocate(n);     ... Read More

Add a Value to Triplet Class in Javatuples

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

228 Views

The addAtX() method is used to add value to the Triplet Tuple. The index can be set here with the X i.e. the place where the value gets added.Let us first see what we need to work with JavaTuples. To work with Triplet class in JavaTuples, you need to import the following package −import org.javatuples.Triplet;Here, we have used Quartet class also, therefore import the following −import org.javatuples.Quartet;Note − Steps to download and run JavaTuples program If you are using Eclipse IDE to run Triplet Class in JavaTuples, then Right Click Project → Properties → Java Build Path → Add External ... Read More

Select ID Column as NULL in MySQL

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

626 Views

Let us first create a table. The query to create a table is as followsmysql> create table selectAllDemo - > ( - > Name varchar(100), - > Age int - > ); Query OK, 0 rows affected (1.90 sec)Insert some records in the table using insert command.The query is as followsmysql> insert into selectAllDemo values('John', 25); Query OK, 1 row affected (0.99 sec) mysql> insert into selectAllDemo values('Carol', 26); Query OK, 1 row affected (0.42 sec) mysql> insert into selectAllDemo values('Bob', 30); Query OK, 1 row affected (1.57 ... Read More

Get Default Phone Network Operator Name in Android

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

1K+ Views

This example demonstrate about How to get default phone Network operator name in android.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 a text view to show the phone network operator name.Step 3 − Add the following code to java/MainActivity.xmlpackage com.example.myapplication; import android.Manifest; import android.content.Context; import android.content.pm.PackageManager; import android.os.Build; import android.os.Bundle; import android.support.annotation.NonNull; import android.support.annotation.RequiresApi; import android.support.v4.app.ActivityCompat; import android.support.v7.app.AppCompatActivity; import android.telephony.TelephonyManager; import android.widget.TextView; ... Read More

LongStream map Method in Java

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

157 Views

The map() method of the LongStream class in Java returns a stream consisting of the results of applying the given function to the elements of this stream.The syntax is as follows:LongStream map(LongUnaryOperator mapper)Here, the parameter mapper is a stateless function to apply to each element. The LongUnaryOperator represents an operation on a single long-valued operand that produces a long-valued result.To use the LongStream class in Java, import the following package:import java.util.stream.LongStream;Create a LongStream and add some elements:LongStream longStream1 = LongStream.of(15L, 30L, 45L, 67L, 80L);Now, create another LongStream and map it to a condition set for the elements of longStream1:LongStream longStream2 ... Read More

Advertisements