Found 33676 Articles for Programming

The clear() method of Java AbstractCollection class

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

181 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

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

117 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

How to set/insert null values to in to a column of a row using JDBC program?

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

7K+ Views

You can insert null values into a table in SQL in two ways:Directly inserting the value NULL into the desired column as:Insert into SampleTable values (NULL);Using ‘ ’ as nullInsert into SampleTable values (NULL);While inserting data into a table using prepared statement object you can set null values to a column using the setNull() method of the PreparedStatement interface.pstmt.setNull(parameterIndex, sqlType);ExampleAssume we have a table named cricketers_data in the database with the following contents:+------------+------------+---------------+----------------+-------------+ | First_Name | Last_Name  | Date_Of_Birth | Place_Of_Birth | Country | +------------+------------+---------------+----------------+-------------+ | Shikhar    | Dhawan     | 1981-12-05    | ... Read More

The hashCode() method of AbstractList class in Java

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

102 Views

The hashCode() method of AbstractList class returns the hash code value for this list.The syntax is as follows:public int hashCode()To work with the AbstractList class, import the following package:import java.util.AbstractList;The following is an example to implement hashCode() 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();       myList.add(50);       myList.add(100);       myList.add(150);       myList.add(200);       myList.add(250);       myList.add(300);       myList.add(350);       myList.add(400);   ... Read More

The set() method of AbstractList class in Java

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

103 Views

The set() method of the AbstractList class is used to replace the element at the specified position in this list with the specified element. It returns the element that gets replaced.The syntax is as follows:public E set(int index, E ele)Here, the parameter index is the index of the element to replace, whereas ele is the element to be stored at the specified position.To work with the AbstractList class, import the following package:import java.util.AbstractList;The following is an example to implement set() method of the AbstractlList class in Java:Example Live Demoimport java.util.LinkedList; import java.util.AbstractList; public class Demo {    public static void main(String[] ... Read More

vector::resize() vs vector::reserve() in C++

karthikeya Boyini
Updated on 06-May-2025 17:31:12

891 Views

Vectors have the ability to resize itself automatically like dynamic arrays when an element is inserted or deleted, the container handle their storage automatically. The main difference between vector resize() and vector reserve() is that resize() is used to change the size of vector where reserve() doesn’t. reserve() is only used to store at least the number of the specified elements without having to reallocate memory. But in resize() if the number is smaller than the current number then it resizes the memory and deletes the excess space over it. C++ vector::resize() The resize() is used to change the actual ... Read More

The get() method of AbstractList class in Java

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

174 Views

The get() method of the AbstractList class is used to get the element at the specified position in the list. It returns the element at the position set as parameter.The syntax is as follows:public abstract E get(int index)Here, index is the index of the element to return.To work with the AbstractList class, import the following package:import java.util.AbstractList;The following is an example to implement get() method of the AbstractlList class in Java:Exampleimport java.util.LinkedList; import java.util.AbstractList; public class Demo {    public static void main(String[] args) {       AbstractList myList = new LinkedList();       myList.add(50);       ... Read More

std::vector::resize() vs. std::vector::reserve() in C++

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

3K+ Views

Vectors have the ability to resize itself automatically like dynamic arrays when an element is inserted or deleted, the container handle their storage automatically.The main difference between vector resize() and vector reserve() is that resize() is used to change the size of vector where reserve() doesn’t. reserve() is only used to store at least the number of the specified elements without having to reallocate memory. But in resize() if the number is smaller than the current number then it resizes the memory and deletes the excess space over it.vector::resize()Vector resize() is used to change its size.ExampleSteps in the source code:Begin ... Read More

How to add elements to AbstractList class in Java?

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

415 Views

To add elements to AbstractList class, the add() method is provided by the AbstractList class. The elemnt gets appended at the end of the list.The syntax is as follows:public boolean add(E ele)Here, the parameter ele is an element to be appended to this listTo work with the AbstractList class, import the following package:import java.util.AbstractList;The following is an example to add elements to AbstractlList class in Java:Example Live Demoimport java.util.LinkedList; import java.util.AbstractList; public class Demo {    public static void main(String[] args) {       AbstractList myList = new LinkedList();       myList.add(50);       myList.add(100);       ... Read More

What is AbstractList Class in Java?

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

739 Views

The AbstractList class provides an implementation of the List interface.For an unmodifiable listProgrammer needs to extend this class and provide implementations for the get(int) and size() methods.For a modifiable listProgrammer must override the set(int, E) method. If the list is variable-size the programmer must override the add(int, E) and remove(int) methods.The following is the syntax:public abstract class AbstractList extends AbstractCollection implements ListTo work with the AbstractList class, import the following package:import java.util.AbstractList;The following is an example to implement AbstractList class:Example Live Demoimport java.util.LinkedList; import java.util.AbstractList; public class Demo {    public static void main(String[] args) {       AbstractList myList ... Read More

Advertisements