ByteBuffer Compact Method in Java

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

286 Views

The buffer can be compacted using the compact() method in the class java.nio.ByteBuffer. This method does not require a parameter and it returns the new compacted ByteBuffer with the same content as the original buffer. If the buffer is read-only, then the ReadOnlyBufferException is thrown.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 buffer ... Read More

Duration hashCode Method in Java

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

172 Views

The hash code value of the duration can be obtained using the hashCode() method in the Duration class in Java. This method requires no parameters and it returns the hash code value of the duration.A program that demonstrates this is given as follows −Example Live Demoimport java.time.Duration; public class Demo { public static void main(String[] args) { Duration d = Duration.ofDays(2); System.out.println("The duration is: " + d); System.out.println("The hash code of the duration is: " + d.hashCode()); ... Read More

Create Triplet Tuple from Array in Java

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

153 Views

To create a Triplet tuple from Array in Java, you need to use the fromArray() method.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;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 Jars and upload the downloaded JavaTuples jar file.The following is an example −Exampleimport java.util.*; import org.javatuples.Triplet; public class Demo {    public static void main(String[] ... Read More

Split a String and Insert into MySQL Table

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

841 Views

You can achieve this with the help of prepared statement in MySQL. First you need to create a table. The query to create a table is as followsmysql> create table University - > ( - > UserId int, - > UniversityId int - > ); Query OK, 0 rows affected (0.64 sec)At first, let us set values in the above-mentioned columns. Here, we have set a string with comma separated value for UserId column. We will split this and insert in the tablemysql> SET @userId = '8, 9, ... Read More

Get Default Phone MMS User Agent in Android

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

139 Views

This example demonstrate about How to get default phone MmsUserAgent 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 phone MmsUserAgent.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; import static android.Manifest.permission.READ_PHONE_NUMBERS; import static android.Manifest.permission.READ_PHONE_STATE; ... Read More

Instant Plus Method in Java

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

2K+ Views

An immutable copy of a instant where a time unit is added to it can be obtained using the plus() method in the Instant class in Java. This method requires two parameters i.e. time to be added to the instant and the unit in which it is to be added. It also returns the immutable copy of the instant where the required time unit is added.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 ... Read More

Instant HashCode Method in Java

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

191 Views

The hash code for a particular Instant object can be obtained using the hashCode() method in the Instant class in Java. This method requires no parameters and it returns the hash code for the Instant object.A program that demonstrates this is given as followsExample 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);       int hashCode = i.hashCode();       System.out.println("The Hash Code value for the instant is: " + hashCode);    } }OutputThe ... Read More

Generate Infinite Stream of Integers in Java Using IntStream.generate

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

170 Views

You can also generate Infinite Stream of Integers in Java with IntStream.generate() method. Here, we have used the Random class to get the list of random integers:Random r = new Random();After that use IntStream.generate() and the nextInt() method gets the next random integer:IntStream.generate(r::nextInt)The following is an example displaying how to generate Infinite Stream of Integers with IntStream.generate() in Java:import java.util.stream.*; import java.util.*; public class Main {    public static void main(String[] args) {       Random r = new Random();       IntStream.generate(r::nextInt).forEach(System.out::println);    } }Here is the output:565757777 3535363636 9879879879 -686549988Read More

Top 10 Most Occurring Values in a Column in MySQL

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

1K+ Views

To count the top 10 most occurring values in a column in MySQL, The syntax is as follows −SELECT yourColumnName, count(*)    FROM yourTableName    GROUP BY yourColumnName    ORDER BY count(*) DESC    LIMIT 10;To understand the above syntax, let us create a table. The query to create a table is as follows −mysql> create table countTop10Demo    -> (    -> Value int    -> ); Query OK, 0 rows affected (0.74 sec)Insert some records in the table using insert command. The query is as follows −mysql> insert into countTop10Demo values(10); Query OK, 1 row affected (0.12 sec) ... Read More

Check if MongoDB Database is 64 Bits

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

126 Views

You can use buidInfo along with runCommand to check MongoDB for 32 bits or 64 bits. First switch your database to admin. Following is the syntaxuse adminAfter that use the following syntax to know if my server runs MongoDB 64 bits or notdb.runCommand(buildInfo)Now execute the above syntax> use admin switched to db admin > db.runCommand("buildInfo");Following is the output displaying MongoDB is 64 bits{    "version" : "4.0.5",    "gitVersion" : "3739429dd92b92d1b0ab120911a23d50bf03c412",    "targetMinOS" : "Windows 7/Windows Server 2008 R2",    "modules" : [ ],    "allocator" : "tcmalloc",    "javascriptEngine" : "mozjs",    "sysInfo" : "deprecated",    "versionArray" : [ ... Read More

Advertisements