Found 4336 Articles for Java 8

The get() method of CopyOnWriteArrayList in Java

Naveen Singh
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

Naveen Singh
Updated on 30-Jul-2019 22:30:25

253 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?

Naveen Singh
Updated on 30-Jul-2019 22:30:25

672 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?

Naveen Singh
Updated on 30-Jul-2019 22:30:25

1K+ 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?

Naveen Singh
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?

Naveen Singh
Updated on 30-Jul-2019 22:30:25

363 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

Naveen Singh
Updated on 30-Jul-2019 22:30:25

79 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

How to create and release a save point in JDBC?

Naveen Singh
Updated on 30-Jul-2019 22:30:25

740 Views

When you set a save point you define a logical rollback point within a transaction. If an error occurs past a save point, you can use the rollback method to undo either all the changes or only the changes made after the save point.Savepoint interface gives you the additional transactional control. Most modern DBMS, support save points within their environments such as Oracle's PL/SQL.Setting a save pointYou can set a save point in a database using the setSavepoint(String savepointName) method of the Connection interface, this method accepts a string value representing the name of the save point and returns a ... Read More

The clear() method of Java AbstractCollection class

Naveen Singh
Updated on 30-Jul-2019 22:30:25

126 Views

The clear() method of the AbstractCollection class is used to remove all the elements from this collection. This makes the collection empty.The syntax is as follows:public void clear()To work with AbstractCollection class in Java, import the following package:import java.util.AbstractCollection;First, create AbstractCollection and add some elements using the add() method:AbstractCollection absCollection = new ArrayList(); absCollection.add("These"); absCollection.add("are"); absCollection.add("demo"); absCollection.add("elements");Now, clear the AbstractCollection:absCollection.clear();The following is an example to implement AbstractCollection clear() 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("These");     ... Read More

The addAll() method of Java AbstractCollection class

Naveen Singh
Updated on 30-Jul-2019 22:30:25

83 Views

The addAll() method of the AbstractCollection class in Java is used to add all of elements in the specified collection to this collection. It returns TRUE if the elements are successfully appendedThe syntax is as follows:public boolean addAll(Collection

Advertisements