The Vector elements can be traversed using the Enumeration interface. The method hasMoreElements( ) returns true if there are more elements to be enumerated and false if there are no more elements to be enumerated. The method nextElement( ) returns the next object in the enumeration.A program that demonstrates this is given as follows −Example Live Demoimport java.util.Enumeration; import java.util.Vector; public class Demo { public static void main(String args[]) { Vector vec = new Vector(); vec.add(7); vec.add(3); vec.add(5); vec.add(9); vec.add(2); ... Read More
An Iterator can be used to loop through the Vector elements. The method hasNext( ) returns true if there are more elements in the Vector and false otherwise. The method next( ) returns the next element in the Vector and throws the exception NoSuchElementException if there is no next element.A program that demonstrates this is given as follows −Example Live Demoimport java.util.Iterator; import java.util.Vector; public class Demo { public static void main(String args[]) { Vector vec = new Vector(); vec.add(4); vec.add(1); vec.add(3); vec.add(9); ... Read More
A ListIterator can be used to traverse the elements in the forward direction as well as the reverse direction in a Vector. The method hasNext( ) in ListIterator returns true if there are more elements in the Vector while traversing in the forward direction and false otherwise. The method next( ) returns the next element in the Vector and advances the cursor position.A program that demonstrates this is given as follows −Exampleimport java.util.ListIterator; import java.util.Vector; public class Demo { public static void main(String args[]) { Vector vec = new Vector(); vec.add(3); ... Read More
The maximum element of a Vector can be obtained using the java.util.Collections.max() method. This method contains a single parameter i.e. the Vector whose maximum element is determined and it returns the maximum element from the Vector.A program that demonstrates this is given as follows −Example Live Demoimport java.util.Collections; import java.util.Vector; public class Demo { public static void main(String args[]) { Vector vec = new Vector(); vec.add(7); vec.add(3); vec.add(9); vec.add(5); vec.add(8); System.out.println("The Vector elements are: " + vec); ... Read More
The minimum element of a Vector can be obtained using the java.util.Collections.min() method. This method contains a single parameter i.e. the Vector whose minimum element is determined and it returns the minimum element from the Vector.A program that demonstrates this is given as follows −Example Live Demoimport java.util.Collections; import java.util.Vector; public class Demo { public static void main(String args[]) { Vector vec = new Vector(); vec.add(7); vec.add(3); vec.add(9); vec.add(5); vec.add(8); System.out.println("The Vector elements are: " + vec); ... Read More
A Vector can be converted into an Array using the java.util.Vector.toArray() method. This method requires no parameters and it returns an Array that contains all the elements of the Vector in the correct order.A program that demonstrates this is given as follows −Example Live Demoimport java.util.Vector; public class Demo { public static void main(String args[]) { Vector vec = new Vector(); vec.add(7); vec.add(3); vec.add(5); vec.add(2); vec.add(8); Object[] arr = vec.toArray(); System.out.println("The Array elements are: "); ... Read More
A Vector can be cloned using the java.util.Vector.clone() method. This method does not take any parameters but returns a clone of the specified Vector instance as an object.A program that demonstrates this is given as follows −Example Live Demoimport java.util.Vector; public class Demo { public static void main(String args[]) { Vector vec1 = new Vector(); vec1.add(7); vec1.add(3); vec1.add(5); vec1.add(9); vec1.add(2); Vector vec2 = (Vector) vec1.clone(); System.out.println("The Vector vec1 elements are: " + vec1); ... Read More
The objects of a user defined class can be ordered using the Comparator interface in Java. The java.util.Collections.reverseOrder() method reverses the order of an element collection using a Comparator.A program that demonstrates this is given as follows −Exampleimport java.util.Arrays; import java.util.Collections; import java.util.Comparator; public class Demo { public static void main(String args[]) throws Exception { Comparator comparator = Collections.reverseOrder(); { "John", "Amy", "Susan", "Peter" }; int n = str.length; System.out.println("The array elements are: "); for (int i = 0; i < n; i++) { ... Read More
To filter specific values, use $filter in MongoDB. Let us create a collection with documents −> db.demo751.insertOne( ... { ... _id: 101, ... details: [ ... { Name: "Robert", id:110, Age:21}, ... { Name: "Rae", id:110, Age:22}, ... {Name: "Ralph", id:116, Age:23} ... ] ... } ... ); { "acknowledged" : true, "insertedId" : 101 }Display all documents from a collection with the help of find() method −> db.demo751.find().pretty();This will produce the following output −{ "_id" ... Read More
In this article, we will learn how to determine whether a string is “pangram” or not in Python 3.x. Or earlier. A pangram string contains every letter in the list of English language alphabets . Let us look at the illustration below −Provided Input: str = 'This is the python blog on Tutorial point' Desired Output: No Provided Input : str='I want to contribute to a 'dxyzwuvghlkfmq' open source project' Desired Output: YesBy definition, a perfect pangram includes every letter of the ‘26 English alphabets’ exactly once. This tutorial doesn’t include the concept of ‘perfect pangram’.Now Let’s look at the ... Read More