Duration toMillis Method in Java

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

186 Views

The value of a particular duration in the number of milliseconds can be obtained using the toMillis() method in the Duration class in Java. This method requires no parameters and it returns the duration in the number of milliseconds.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.ofSeconds(1);       System.out.println("The duration is: " + d);       System.out.println("The number of milliseconds in the duration is: " + d.toMillis());    } }OutputThe duration is: PT1S The number of ... Read More

Convert Positive Value to Negative in MySQL

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

2K+ Views

Let us first create a tablemysql> create table recordsDemo    -> (    -> UserId int,    -> Value int    -> ); Query OK, 0 rows affected (0.52 sec)Now insert some records in the table using insert command.The query is as followsmysql> insert into recordsDemo values(1, 10); Query OK, 1 row affected (0.17 sec) mysql> insert into recordsDemo values(3, 598); Query OK, 1 row affected (0.18 sec) mysql> insert into recordsDemo values(5, 786); Query OK, 1 row affected (0.25 sec) mysql> insert into recordsDemo values(7, 189); Query OK, 1 row affected (0.16 sec) mysql> insert into recordsDemo values(9, 345); ... Read More

Convert Character Array to IntStream in Java

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

643 Views

Let’s say the following is our character array:Character arr[] = { 'V', 'e', 'h', 'i', 'c', 'l' , 'e' };To convert the above character array to IntStreamIntStream stream = Stream.of(arr).flatMapToInt(IntStream::of);We have used the flatMapToInt() method for this.The following is an example to convert character array to IntStream in Java:Example Live Demoimport java.util.stream.*; public class Main {    public static void main(String[] args) {       Character arr[] = { 'V', 'e', 'h', 'i', 'c', 'l' , 'e' };       System.out.println("The character array = ");       for (char value : arr) {          System.out.println("Value ... Read More

Get Headset from TreeSet in Java

Krantik Chavan
Updated on 30-Jul-2019 22:30:25

148 Views

To get HeadSet from TreeSet, at first create a TreeSet and add some elements:TreeSet treeSet = new TreeSet(); treeSet.add("ABC"); treeSet.add("DEF"); treeSet.add("GHI"); treeSet.add("JKL"); treeSet.add("MNO"); treeSet.add("PQR");To get headset, use the headset() method:SortedSet set = treeSet.headSet("MNO"); System.out.println("Head Set = " + set);You can also change the value like this:set = treeSet.headSet("GHI"); System.out.println("Head Set = " + set);Exampleimport java.util.SortedSet; import java.util.TreeSet; public class Demo {    public static void main(String[] args) {       TreeSet treeSet = new TreeSet();       treeSet.add("ABC");       treeSet.add("DEF");       treeSet.add("GHI");       treeSet.add("JKL");       treeSet.add("MNO");       treeSet.add("PQR"); ... Read More

Get Names of MySQL Table Columns

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

523 Views

You can use SHOW command for this. Following is the syntax −show columns from yourTableName;Let us first create a table −mysql> create table DemoTable (    StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY,    StudentFirstName varchar(20),    StudentLastName varchar(20),    StudentAge int,    StudentAddress varchar(200) ); Query OK, 0 rows affected (0.54 sec)Following is the query to get the names of my MySQL table columns −mysql> show columns from DemoTable;This will produce the following output −+------------------+--------------+------+-----+---------+----------------+ | Field | Type | Null ... Read More

FloatBuffer equals Method in Java

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

167 Views

The equality of two buffers can be checked using the method equals() in the class java.nio.FloatBuffer. Two buffers are equal if they have the same type of elements, the same number of elements and same sequence of elements. The method equals() returns true if the buffers are equal and false otherwise.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 {          FloatBuffer buffer1 = FloatBuffer.allocate(n);          buffer1.put(4.5F); ... Read More

Linear Regression Using PyTorch

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

606 Views

About Linear RegressionSimple Linear Regression BasicsAllows us to understand relationship between two continuous variable.Example −x = independent variableweighty = dependent variableheighty = αx + βLet's understand simple linear regression through a program −#Simple linear regression import numpy as np import matplotlib.pyplot as plt np.random.seed(1) n = 70 x = np.random.randn(n) y = x * np.random.randn(n) colors = np.random.rand(n) plt.plot(np.unique(x), np.poly1d(np.polyfit(x, y, 1))(np.unique(x))) plt.scatter(x, y, c = colors, alpha = 0.5) plt.show()OutputPurpose of Linear Regression:to Minimize the distance between the points and the line (y = αx + β)AdjustingCoefficient: αIntercept/Bias: βBuilding a Linear Regression Model with PyTorchLet's ... Read More

Use REPLACE Command in Android SQLite

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

477 Views

Before getting into example, we should know what sqlite data base in android is. SQLite is an open source SQL database that stores data to a text file on a device. Android comes in with built in SQLite database implementation. SQLite supports all the relational database features. In order to access this database, you don't need to establish any kind of connections for it like JDBC, ODBC etc.This example demonstrate about How to use replace command in Android sqlite.Step 1 − Create a new project in Android Studio, go to File ⇒ New Project and fill all required details to ... Read More

Set Minimum Capacity for ArrayList in Android

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

157 Views

This example demonstrates How to set minimum capacity for arraylist Listview 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 name and record number as Edit text, when user click on save button it will store the data into arraylist. Click on refresh button to get ... Read More

Use SortedSet Interface in Android

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

256 Views

This example demonstrate about How to use Sorted set interface in AndroidStep 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 the name and record number as Edit text, when user click on save button it will store the data into arraylist. Click on the refresh button to get the ... Read More

Advertisements