Remove all elements from vector in java

The clear() method is used to delete or remove all elements of a vector at one call in java. Syntax: vector.clear() Example: package com.w3schools;   import java.util.Vector;   public class Test { public static void main(String args[]){ Vector<String> vector = new Vector<String>(); //adding elements to the end vector.add("Jai"); vector.add("Mahesh"); vector.add("Hemant"); vector.add("Vishal"); System.out.println("Actual vector:"+vector); vector.clear(); System.out.println("After … Read more

Add all elements of a list to vector in java

The addAll() method is used to add all elements of a list to vector in java. Syntax: boolean addAll(Collection C) Example: package com.w3schools;   import java.util.ArrayList; import java.util.List; import java.util.Vector;   public class Test { public static void main(String args[]){ Vector<String> vector = new Vector<String>(); //adding elements to the end vector.add("Jai"); vector.add("Mahesh"); vector.add("Hemant"); vector.add("Vishal"); System.out.println("Actual … Read more

Copy or clone a vector in java

The clone() method is used to create similar copy of vector in java. Syntax: Vector.clone() Example: package com.w3schools;   import java.util.Vector;   public class Test { public static void main(String args[]){ Vector<String> vector = new Vector<String>(); //adding elements to the end vector.add("Jai"); vector.add("Mahesh"); vector.add("Hemant"); vector.add("Vishal"); System.out.println("Actual vector:"+vector); Vector<String> copy = (Vector<String>) vector.clone(); System.out.println("Cloned vector:"+copy); } … Read more

Read all elements in vector

We can read all elements in vector by following ways: Read all elements in vector using iterator. Read all elements in vector using Enumeration. Read all elements in vector using iterator package com.w3schools;   import java.util.Iterator; import java.util.Vector;   /** * Read all elements in vector using iterator * @author w3schools */ public class ReadVectorElements … Read more

Vector class in Java

The java.util.Vector class implements a growable array of objects. Like an array, it contains components that can be accessed using an integer index. However, the size of a Vector can grow or shrink as needed to accommodate adding and removing items after the Vector has been created. It extends AbstractList and implements List interfaces. Vector … Read more

Remove element from collection

We can remove elements from java collection by following ways: Removing collection elements using Iterator Removing collection elements using Collection.removeIf() Removing collection elements using Stream filter Removing collection elements using Iterator package com.w3schools;   import java.util.ArrayList; import java.util.Iterator; import java.util.List;   /** * Removing collection elements using Iterator * @author w3schools */ public class RemoveCollectionElements … Read more

Iterate collection objects in java

We can iterate collection objects by following 4 ways: Using Classic For Loop Using Iterator Method Using Enhanced For Loop Using forEach Method with Lambda Expressions Using Classic For Loop package com.w3schools;   import java.util.ArrayList; import java.util.List;   /** * Iterate collection objects using Classic For Loop * @author w3schools */ public class IterateCollection { … Read more

ListIterator interface in java

ListIterator: ListIterator interface is used to traverse the elements in both forward and backward directions. Note: Can traverse elements in both forward and backward directions. Commonly Used methods of ListIterator Interface: 1. hasNext(): Returns true if iterator has more elements in forward direction otherwise returns false. Syntax: public boolean hasNext(). 2. next(): Returns the element … Read more

Hashtable in java

Java Hashtable: Hashtable extends Dictionary class and implements Map interface. It contains elements in key-value pairs. It is not allowed duplicate keys. It is synchronized. It can’t contain a null key or value. It uses the hashcode() method for finding the position of the elements. Note: It is an array of a list. Each list … Read more

Properties class in java

Properties class: Properties class is used to maintain the data in the key-value form. It takes both key and value as a string. Properties class is a subclass of Hashtable. It provides the methods to store properties in a properties file and to get the properties from the properties file. System.getProperties() returns the all system … Read more