Found 7442 Articles for Java

ArrayBlockingQueue put() method in Java

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

121 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

153 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

473 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

108 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

321 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

How to get the number of columns of a table using JDBC?

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

950 Views

You can get the number of columns of a table using the getColumnCount() method of the ResultSetMetaData class.//Retrieving the ResultSetMetaData object ResultSetMetaData rsmd = rs.getMetaData(); //getting the column type int column_count = rsmd.getColumnCount();Assume we have a table named employee_data in the database with description as shown below:+----------+--------------+------+-----+---------+-------+ | Field    | Type         | Null | Key | Default | Extra | +----------+--------------+------+-----+---------+-------+ | id       | int(11)      | YES  |     | NULL    |       | | Name     | varchar(255) | YES  |     ... Read More

How to get the size of a column of a table using JDBC?

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

2K+ Views

You can get the size of a column of a table using the getPrecision() method of the ResultSetMetaData class.//Retrieving the ResultSetMetaData object ResultSetMetaData rsmd = rs.getMetaData(); //getting the column type int size_name = rsmd. getPrecision(3);Assume we have a table named employee_data in the database with description as shown below:+----------+--------------+------+-----+---------+-------+ | Field    | Type         | Null | Key | Default | Extra | +----------+--------------+------+-----+---------+-------+ | id       | int(11)      | YES  |     | NULL    |       | | Name     | varchar(255) | YES  | ... Read More

How to get the datatype of a column of a table using JDBC?

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

3K+ Views

You can get the datatype of a column of a table using the getColumnType() method of the ResultSetMetaData class.//Retrieving the ResultSetMetaData object ResultSetMetaData rsmd = rs.getMetaData(); //getting the column type String column_name = rsmd.getColumnTypeName(2);Assume we have a table named employee_data in the database with the description as shown below:+----------+--------------+------+-----+---------+-------+ | Field    | Type         | Null | Key | Default | Extra | +----------+--------------+------+-----+---------+-------+ | id       | int(11)      | YES  |     | NULL    | | | Name     | varchar(255) ... Read More

How to get the number of records in a table using JDBC?

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

492 Views

The ResultSet class doesn’t provide any direct method to get the number of records in a table.The beforeFirst() method navigates the pointer/curser of the ResultSet object to its default position before first.In the same way the last() method positions the cursor at the last row of the ResultSet object.Using these methods you can find the number of records in the current ResultSet object.ExampleAssume we have a table named customers table with contents as shown below:+----+---------+-----+---------+----------------+ | ID | NAME    | AGE | SALARY  | ADDRESS        | +----+---------+-----+---------+----------------+ | 1  | Amit    | 25  | 3000.00 ... Read More

The contains() method of Java AbstractCollection class

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

129 Views

The contains() method of the AbstractCollection class checks whether an element is in the AbstractCollection or not. It returns a Boolean i.e. TRUE if the element is in the collection, else FALSE is returned.The syntax is as follows:public boolean contains(Object ele)Here, ele is the element to be checked for existence.To work with AbstractCollection class in Java, import the following package:import java.util.AbstractCollection;The following is an example to implement AbstractCollection contains() method in Java:Example Live Demoimport java.util.ArrayList; import java.util.AbstractCollection; public class Demo {    public static void main(String[] args) {       AbstractCollection absCollection = new ArrayList();       absCollection.add("Football");   ... Read More

Advertisements