Found 4332 Articles for Java 8

Create KeyValue Tuple from a List collection in Java

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

79 Views

To create KeyValue tuple from List collection, use the fromCollection() method. Let us first see what we need to work with JavaTuples. To work with KeyValue class in JavaTuples, you need to import the following package:import org.javatuples.KeyValue;Note: Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file. Refer the below guide for all the steps to run JavaTuples:Steps: How to run JavaTuples program in EclipseThe following is an example to create KeyValue Tuple from List ... Read More

How to move the result set pointer to required position?

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

183 Views

The absolute() method of the ResultSet interface accepts an integer value representing the index of a row and moves the ResultSet pointer of the current ResultSet object to the specified position.Assume we have a table named cricketers_data with 6 records as shown below:+------------+------------+---------------+----------------+-------------+ | First_Name | Last_Name  | Date_Of_Birth | Place_Of_Birth | Country     | +------------+------------+---------------+----------------+-------------+ | Shikhar    | Dhawan     | 1981-12-05    | Delhi          | India       | | Jonathan   | Trott      | 1981-04-22    | CapeTown       | SouthAfrica | | Lumara   ... Read More

DoubleStream average() method in Java

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

1K+ Views

The average() method of the DoubleStream class in Java returns an OptionalDouble which is the arithmetic mean of elements of this stream. If the stream is empty, empty is returned.The syntax is as follows:OptionalDouble average()Here, OptionalDouble is a container object which may or may not contain a double value.To use the DoubleStream class in Java, import the following package:import java.util.stream.DoubleStream;First, create DoubleStream and add some elements:DoubleStream doubleStream = DoubleStream.of(50.8, 35.7, 49.5, 12.7, 89.7, 97.4);Get the average of the elements of the stream:OptionalDouble res = doubleStream.average();The following is an example to implement DoubleStream average() method in Java:Example Live Demoimport java.util.*; import java.util.stream.DoubleStream; ... Read More

Create Octet Tuple from an array in Java

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

95 Views

To create Octet Tuple from an array in Java, use the fromArray() method. Let us first see what we need to work with JavaTuples. To work with Octet class in JavaTuples, you need to import the following package:import org.javatuples.Octet;Note: Download JavaTuples Jar library to run JavaTuples program. If you are using Eclipse IDE, then Right Click Project → Properties → Java Build Path → Add External Jars and upload the downloaded JavaTuples jar file. Refer the below guide for all the steps to run JavaTuples:Steps: How to run JavaTuples program in EclipseThe following is an example to create Octet Tuple ... Read More

How to delete a row from ResultSet object using JDBC?

Nitya Raut
Updated on 30-Jul-2019 22:30:25

864 Views

The deleteRow() method of the ResultSet interface deletes the current row from the current ResultSet object.//Deleting a column from the ResultSet object rs.deleteRow();Assume we have a table named Cricketers_Data with 6 records as shown below:+----+------------+------------+---------------+----------------+-------------+ | ID | First_Name | Last_Name  | Year_Of_Birth | Place_Of_Birth | Country     | +----+------------+------------+---------------+----------------+-------------+ | 1  | Shikhar    | Dhawan     | 1981-12-05    | Delhi          | India | | 2  | Jonathan   | Trott      | 1981-04-22    | CapeTown       | SouthAfrica | | 3 ... Read More

ArrayBlockingQueue put() method in Java

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

82 Views

The put() method of the ArrayBlockingQueue class inserts the specified element at the tail of this queue. It waits for the space to become available, if the queue is full.The syntax is as follows:void put(E e)Here, e is the element to be inserted.To work with ArrayBlockingQueue class, you need to import the following package:import java.util.concurrent.ArrayBlockingQueue;The following is an example to implement put() method of Java ArrayBlockingQueue class:Example Live Demoimport java.util.concurrent.ArrayBlockingQueue; public class Demo {    public static void main(String[] args) throws InterruptedException {       ArrayBlockingQueue q = new ArrayBlockingQueue(7);       q.put(200);       q.put(310);     ... Read More

DoubleStream forEach() method in Java

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

101 Views

The forEach() method of the DoubleStream class performs an action for each element of this stream.The syntax is as follows:void forEach(DoubleConsumer action)Here, DoubleConsumer represents an operation that accepts a single double-valued argument and returns no result. The parameter action is a non-interfering action to perform on the elements.To use the DoubleStream class in Java, import the following package:import java.util.stream.DoubleStream;Create a DoubleStream and add some elements to the stream:DoubleStream doubleStream = DoubleStream.of(45.7, 67.8, 89.7, 95.6);Now, display the elements:doubleStream.forEach(System.out::println);The following is an example to implement DoubleStream forEach() method in Java:Example Live Demoimport java.util.stream.DoubleStream; public class Demo {    public static void main(String[] args){ ... Read More

How to create a table in JDBC using another table?

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

349 Views

You can create a table same as an existing table using the following syntax:CREATE TABLE new_table as SELECT * from old_table;Assume we have a table named dispatches with 5 records as shown below:+-------------+--------------+--------------+--------------+-------+----------------+ | ProductName | CustomerName | DispatchDate | DeliveryTime | Price | Location       | +-------------+--------------+--------------+--------------+-------+----------------+ | Key-Board   | Raja         | 2019-09-01   | 05:30:00     | 7000  | Hyderabad     | | Earphones   | Roja         | 2019-05-01   | 05:30:00     | 2000  | Vishakhapatnam | | Mouse       ... Read More

The get() method of CopyOnWriteArrayList in Java

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

67 Views

The get() method of CopyOnWriteArrayList class returns the element at the specified position in this list.The syntax is as follows:E get(int index)Here, the parameter index is the position from where you want the element.To work with CopyOnWriteArrayList class, you need to import the following package:import java.util.concurrent.CopyOnWriteArrayList;The following is an example to implement CopyOnWriteArrayList class get() method in Java:Example Live Demoimport java.util.concurrent.CopyOnWriteArrayList; public class Demo {    public static void main(String[] args) {       CopyOnWriteArrayList arrList = new CopyOnWriteArrayList();       arrList.add(100);       arrList.add(250);       arrList.add(400);       arrList.add(500);       arrList.add(650);   ... Read More

The remove() method of AbstractList class in Java

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

256 Views

Remove an element at a specified position from the list using the remove() method. The position is to be set as index parameter in the method itself. It returns the element which is removed.The syntax is as follows:public E remove(int index)Here, index is the index from where you want to delete the element.To work with the AbstractList class, import the following package:import java.util.AbstractList;The following is an example to implement remove() method of the AbstractlList class in Java:Example Live Demoimport java.util.ArrayList; import java.util.AbstractList; public class Demo {    public static void main(String[] args) {       AbstractList myList = new ArrayList(); ... Read More

Advertisements