Question stringlengths 1 113 | Answer stringlengths 22 6.98k |
|---|---|
What are the important points about the Java TreeSet class?
| Java TreeSet class implements the Set interface that uses a tree for storage. It inherits AbstractSet class and implements the NavigableSet interface. The objects of the TreeSet class are stored in ascending order.
The important points about the Java TreeSet class are:
-Java TreeSet class contains unique elements... |
What is Internal Working of The TreeSet Class?
| TreeSet is being implemented using a binary search tree, which is self-balancing just like a Red-Black Tree. Therefore, operations such as a search, remove, and add consume O(log(N)) time. The reason behind this is there in the self-balancing tree. It is there to ensure that the tree height never exceeds O(log(N)) for ... |
What is Synchronization of The TreeSet Class?
| As already mentioned above, the TreeSet class is not synchronized. It means if more than one thread concurrently accesses a tree set, and one of the accessing threads modify it, then the synchronization must be done manually. It is usually done by doing some object synchronization that encapsulates the set. However, in... |
What is the class declaration for TreeSet Class?
| Let's see the declaration for java.util.TreeSet class.
public class TreeSet<E> extends AbstractSet<E> implements NavigableSet<E>, Cloneable, Serializable
|
What are the Constructors of the Java TreeSet Class?
| Constructor: TreeSet()
Description: It is used to construct an empty tree set that will be sorted in ascending order according to the natural order of the tree set.
Constructor: TreeSet(Collection<? extends E> c)
Description: It is used to build a new tree set that contains the elements of the collection c.
Con... |
What are the Methods of Java TreeSet Class?
| Method: boolean add(E e)
Description: It is used to add the specified element to this set if it is not already present.
Method: boolean addAll(Collection<? extends E> c)
Description: It is used to add all of the elements in the specified collection to this set.
Method: E ceiling(E e)
Description: It retu... |
Can you provide an example of Java TreeSet?
| Let's see a simple example of Java TreeSet.
FileName: TreeSet1.java
import java.util.*;
class TreeSet1{
public static void main(String args[]){
//Creating and adding elements
TreeSet<String> al=new TreeSet<String>();
al.add("Ravi");
al.add("Vijay");
al.add("Ravi");
al.add("Aja... |
What is Java Queue Interface?
| The interface Queue is available in the java.util package and does extend the Collection interface. It is used to keep the elements that are processed in the First In First Out (FIFO) manner. It is an ordered list of objects, where insertion of elements occurs at the end of the list, and removal of elements occur at th... |
What is the class declaration for Queue Interface? | public interface Queue<E> extends Collection<E> |
What are the Methods of Java Queue Interface?
| Method: boolean add(object)
Description: It is used to insert the specified element into this queue and return true upon success.
Method: boolean offer(object)
Description: It is used to insert the specified element into this queue.
Method: Object remove()
Description: It is used to retrieves and removes... |
What are the following important features of a Queue?
| The following are some important features of a queue.
-As discussed earlier, FIFO concept is used for insertion and deletion of elements from a queue.
-The Java Queue provides support for all of the methods of the Collection interface including deletion, insertion, etc.
-PriorityQueue, ArrayBlockingQueue and Linke... |
What is the class declaration for PriorityQueue?
| Let's see the declaration for java.util.PriorityQueue class.
public class PriorityQueue<E> extends AbstractQueue<E> implements Serializable
|
Can you provide an example of Java PriorityQueue?
| FileName: TestCollection12.java
import java.util.*;
class TestCollection12{
public static void main(String args[]){
PriorityQueue<String> queue=new PriorityQueue<String>();
queue.add("Amit");
queue.add("Vijay");
queue.add("Karan");
queue.add("Jai");
queue.add("Rahul");
System.out.println("... |
What is Java Deque Interface?
| The interface called Deque is present in java.util package. It is the subtype of the interface queue. The Deque supports the addition as well as the removal of elements from both ends of the data structure. Therefore, a deque can be used as a stack or a queue. We know that the stack supports the Last In First Out (LIFO... |
What is the class declaration for Deque Interface?
| public interface Deque<E> extends Queue<E> |
What are the Methods of Java Deque Interface?
| Method: boolean add(object)
Description: It is used to insert the specified element into this deque and return true upon success.
Method: boolean offer(object)
Description: It is used to insert the specified element into this deque.
Method: Object remove()
Description: It is used to retrieve and removes ... |
What are the important points about ArrayDeque class?
| We know that it is not possible to create an object of an interface in Java. Therefore, for instantiation, we need a class that implements the Deque interface, and that class is ArrayDeque. It grows and shrinks as per usage. It also inherits the AbstractCollection class.
The important points about ArrayDeque class are... |
What is ArrayDeque Hierarchy?
| The hierarchy of ArrayDeque class is given in the figure displayed at the right side of the page. |
What is the class declaration for ArrayDeque class?
| Let's see the declaration for java.util.ArrayDeque class.
public class ArrayDeque<E> extends AbstractCollection<E> implements Deque<E>, Cloneable, Serializable
|
Can you provide an example Java ArrayDeque?
| FileName: ArrayDequeExample.java
import java.util.*;
public class ArrayDequeExample {
public static void main(String[] args) {
//Creating Deque and adding elements
Deque<String> deque = new ArrayDeque<String>();
deque.add("Ravi");
deque.add("Vijay");
deque.add("Ajay"); ... |
What is Java Map Interface?
| A map contains values on the basis of key, i.e. key and value pair. Each key and value pair is known as an entry. A Map contains unique keys.
A Map is useful if you have to search, update or delete elements on the basis of a key.
|
What are the Useful methods of Map interface?
| Method: V put(Object key, Object value)
Description: It is used to insert an entry in the map.
Method: void putAll(Map map)
Description: It is used to insert the specified map in the map.
Method: V putIfAbsent(K key, V value)
Description: It inserts the specified value with the specified key in the map o... |
What is Map.Entry Interface?
| Entry is the subinterface of Map. So we will be accessed it by Map.Entry name. It returns a collection-view of the map, whose elements are of this class. It provides methods to get key and value.
|
What are the Methods of Map.Entry interface?
| Method: K getKey()
Description: It is used to obtain a key.
Method: V getValue()
Description: It is used to obtain value.
Method: int hashCode()
Description: It is used to obtain hashCode.
Method: V setValue(V value)
Description: It is used to replace the value corresponding to this entry with the ... |
Can you provide an example of Java Map: Non-Generic (Old Style)?
|
//Non-generic
import java.util.*;
public class MapExample1 {
public static void main(String[] args) {
Map map=new HashMap();
//Adding elements to map
map.put(1,"Amit");
map.put(5,"Rahul");
map.put(2,"Jai");
map.put(6,"Amit");
//Traversing Map
Set set=ma... |
Can you provide an example of Java Map: Generic (New Style)?
|
import java.util.*;
class MapExample2{
public static void main(String args[]){
Map<Integer,String> map=new HashMap<Integer,String>();
map.put(100,"Amit");
map.put(101,"Vijay");
map.put(102,"Rahul");
//Elements can traverse in any order
for(Map.Entry m:map.entrySet()){
System... |
What is Java HashMap?
| Java HashMap class implements the Map interface which allows us to store key and value pair, where keys should be unique. If you try to insert the duplicate key, it will replace the element of the corresponding key. It is easy to perform operations using the key index like updation, deletion, etc. HashMap class is foun... |
What is the class declaration for HashMap class?
| Let's see the declaration for java.util.HashMap class.
public class HashMap<K,V> extends AbstractMap<K,V> implements Map<K,V>, Cloneable, Serializable
|
What is HashMap class Parameters?
| Let's see the Parameters for java.util.HashMap class.
-K: It is the type of keys maintained by this map.
-V: It is the type of mapped values.
|
What are the Constructors of the Java HashMap?
| Constructor: HashMap()
Description: It is used to construct a default HashMap.
Constructor: HashMap(Map<? extends K,? extends V> m)
Description: It is used to initialize the hash map by using the elements of the given Map object m.
Constructor: HashMap(int capacity)
Description: It is used to initialize... |
What are the Methods of Java HashMap class?
| Method: void clear()
Description: It is used to remove all of the mappings from this map.
Method: boolean isEmpty()
Description: It is used to return true if this map contains no key-value mappings.
Method: Object clone()
Description: It is used to return a shallow copy of this HashMap instance: the keys... |
Can you provide an example of Java HashMap?
| Let's see a simple example of HashMap to store key and value pair.
import java.util.*;
public class HashMapExample1{
public static void main(String args[]){
HashMap<Integer,String> map=new HashMap<Integer,String>();//Creating HashMap
map.put(1,"Mango"); //Put elements in Map
map.put(2,"Ap... |
What is HashMap?
| HashMap is a part of the Java collection framework. It uses a technique called Hashing. It implements the map interface. It stores the data in the pair of Key and Value. HashMap contains an array of the nodes, and the node is represented as a class. It uses an array and LinkedList data structure internally for storing ... |
What is Java LinkedHashMap class?
| Java LinkedHashMap class is Hashtable and Linked list implementation of the Map interface, with predictable iteration order. It inherits HashMap class and implements the Map interface.
Points to remember
-Java LinkedHashMap contains values based on the key.
–Java LinkedHashMap contains unique elements.
Java LinkedH... |
What is the class declaration for LinkedHashMap?
| Let's see the declaration for java.util.LinkedHashMap class.
public class LinkedHashMap<K,V> extends HashMap<K,V> implements Map<K,V>
|
What is LinkedHashMap class Parameters?
| Let's see the Parameters for java.util.LinkedHashMap class.
-K: It is the type of keys maintained by this map.
-V: It is the type of mapped values.
|
What are the Constructors of the Java LinkedHashMap class?
| Constructor: LinkedHashMap()
Description:It is used to construct a default LinkedHashMap.
Constructor:LinkedHashMap(int capacity)
Description:It is used to initialize a LinkedHashMap with the given capacity.
Constructor:LinkedHashMap(int capacity, float loadFactor)
Description:It is used to initialize both the... |
What are the Methods of Java LinkedHashMap class?
| Method: V get(Object key)
Description: It returns the value to which the specified key is mapped.
Method: void clear()
Description: It removes all the key-value pairs from a map.
Method: boolean containsValue(Object value)
Description: It returns true if the map maps one or more keys to the specified val... |
Can you provide an example of Java LinkedHashMap?
| import java.util.*;
class LinkedHashMap1{
public static void main(String args[]){
LinkedHashMap<Integer,String> hm=new LinkedHashMap<Integer,String>();
hm.put(100,"Amit");
hm.put(101,"Vijay");
hm.put(102,"Rahul");
for(Map.Entry m:hm.entrySet()){
System.out.println(m.getK... |
What is Java TreeMap class?
| Java TreeMap class is a red-black tree based implementation. It provides an efficient means of storing key-value pairs in sorted order.
The important points about Java TreeMap class are:
-Java TreeMap contains values based on the key. It implements the NavigableMap interface and extends AbstractMap class.
-Java ... |
What is the class declaration for TreeMap class?
| Let's see the declaration for java.util.TreeMap class.
public class TreeMap<K,V> extends AbstractMap<K,V> implements NavigableMap<K,V>, Cloneable, Serializable
|
What is TreeMap class Parameters?
| Let's see the Parameters for java.util.TreeMap class.
-K: It is the type of keys maintained by this map.
-V: It is the type of mapped values.
|
What are the Constructors of the Java TreeMap class?
| Constructor:TreeMap()
Description:It is used to construct an empty tree map that will be sorted using the natural order of its key.
Constructor:TreeMap(Comparator<? super K> comparator)
Description:It is used to construct an empty tree-based map that will be sorted using the comparator comp.
Constructor:TreeMap... |
What are the Methods of Java TreeMap class?
| Method: Map.Entry<K,V> ceilingEntry(K key)
Description: It returns the key-value pair having the least key, greater than or equal to the specified key, or null if there is no such key.
Method: K ceilingKey(K key)
Description: It returns the least key, greater than the specified key or null if there is no such ... |
Can you provide an example of Java TreeMap?
| import java.util.*;
class TreeMap1{
public static void main(String args[]){
TreeMap<Integer,String> map=new TreeMap<Integer,String>();
map.put(100,"Amit");
map.put(102,"Ravi");
map.put(101,"Vijay");
map.put(103,"Rahul");
for(Map.Entry m:map.e... |
What is Java Hashtable class?
| Java Hashtable class implements a hashtable, which maps keys to values. It inherits Dictionary class and implements the Map interface.
Points to remember
-A Hashtable is an array of a list. Each list is known as a bucket. The position of the bucket is identified by calling the hashcode() method. A Hashtable contains ... |
What is the class declaration for Hashtable class?
| Let's see the declaration for java.util.Hashtable class.
public class Hashtable<K,V> extends Dictionary<K,V> implements Map<K,V>, Cloneable, Serializable
|
What is Hashtable class Parameters?
| Let's see the Parameters for java.util.Hashtable class.
-K: It is the type of keys maintained by this map.
-V: It is the type of mapped values.
|
What are the Constructors of the Java Hashtable class?
| Constructor:Hashtable()
Description:It creates an empty hashtable having the initial default capacity and load factor.
Constructor:Hashtable(int capacity)
Description:It accepts an integer parameter and creates a hash table that contains a specified initial capacity.
Constructor:Hashtable(int capacity, float lo... |
What are the Methods of Java Hashtable class?
| Method: void clear()
Description: It is used to reset the hash table.
Method: Object clone()
Description: It returns a shallow copy of the Hashtable.
Method: V compute(K key, BiFunction<? super K,? super V,? extends V> remappingFunction)
Description: It is used to compute a mapping for the specified key ... |
Can you provide an example of Java Hashtable?
| import java.util.*;
class Hashtable1{
public static void main(String args[]){
Hashtable<Integer,String> hm=new Hashtable<Integer,String>();
hm.put(100,"Amit");
hm.put(102,"Ravi");
hm.put(101,"Vijay");
hm.put(103,"Rahul");
for(Map.Entry m:hm.entrySet()){
System.out.prin... |
What are the Difference between HashMap and Hashtable?
| HashMap and Hashtable both are used to store data in key and value form. Both are using hashing technique to store unique keys.
But there are many differences between HashMap and Hashtable classes that are given below.
1) HashMap is non synchronized. It is not-thread safe and can't be shared between many threads wi... |
What is Java EnumSet class?
| Java EnumSet class is the specialized Set implementation for use with enum types. It inherits AbstractSet class and implements the Set interface.
|
What is the class declaration for EnumSet class?
| Let's see the declaration for java.util.EnumSet class.
public abstract class EnumSet<E extends Enum<E>> extends AbstractSet<E> implements Cloneable, Serializable
|
What are the Methods of Java EnumSet class?
| Method: static <E extends Enum<E>> EnumSet<E> allOf(Class<E> elementType)
Description: It is used to create an enum set containing all of the elements in the specified element type.
Method: static <E extends Enum<E>> EnumSet<E> copyOf(Collection<E> c)
Description: It is used to create an enum set initialized... |
Can you provide an example of Java EnumSet?
| import java.util.*;
enum days {
SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY
}
public class EnumSetExample {
public static void main(String[] args) {
Set<days> set = EnumSet.of(days.TUESDAY, days.WEDNESDAY);
// Traversing elements
Iterator<days> iter = set.itera... |
What is Java EnumMap class?
| Java EnumMap class is the specialized Map implementation for enum keys. It inherits Enum and AbstractMap classes. |
What is the class declaration for EnumMap class?
| Let's see the declaration for java.util.EnumMap class.
public class EnumMap<K extends Enum<K>,V> extends AbstractMap<K,V> implements Serializable, Cloneable
|
What is EnumMap class Parameters?
| Let's see the Parameters for java.util.EnumMap class.
-K: It is the type of keys maintained by this map.
-V: It is the type of mapped values.
|
What are the Constructors of the Java EnumMap class?
| Constructor: EnumMap(Class<K> keyType)
Description: It is used to create an empty enum map with the specified key type.
Constructor: EnumMap(EnumMap<K,? extends V> m)
Description: It is used to create an enum map with the same key type as the specified enum map.
Constructor: EnumMap(Map<K,? extends V> m)
Descr... |
What are the Methods of Java EnumMap class?
|
Sn:1
Method: clear()
Description: It is used to clear all the mapping from the map.
Sn:2
Method:clone()
Description: It is used to copy the mapped value of one map to another map.
Sn:3
Method:containsKey()
Description:It is used to check whether a specified key is present in this map or not.
Sn:... |
Can you provide an example of Java EnumMap?
|
import java.util.*;
public class EnumMapExample {
// create an enum
public enum Days {
Monday, Tuesday, Wednesday, Thursday
};
public static void main(String[] args) {
//create and populate enum map
EnumMap<Days, String> map = new EnumMap<Days, String>(Days.class);
m... |
What is Java Collections class?
| Java collection class is used exclusively with static methods that operate on or return collections. It inherits Object class.
The important points about Java Collections class are:
-Java Collection class supports the polymorphic algorithms that operate on collections.
-Java Collection class throws a NullPointer... |
What is the class declaration for Collections class?
| Let's see the declaration for java.util.Collections class.
public class Collections extends Object
|
Can you provide an example of Java Collections? | import java.util.*;
public class CollectionsExample {
public static void main(String a[]){
List<String> list = new ArrayList<String>();
list.add("C");
list.add("Core Java");
list.add("Advance Java");
System.out.println("Initial collection value:"+list... |
What is Sorting in Collection?
| We can sort the elements of:
-String objects
-Wrapper class objects
-User-defined class objects
Collections class provides static methods for sorting the elements of a collection. If collection elements are of a Set type, we can use TreeSet. However, we cannot sort the elements of List. Collections class provides m... |
What is the Method of Collections class for sorting List elements? | public void sort(List list): is used to sort the elements of List. List elements must be of the Comparable type. |
Can you provide an example to sort string objects?
| import java.util.*;
class TestSort1{
public static void main(String args[]){
ArrayList<String> al=new ArrayList<String>();
al.add("Viru");
al.add("Saurav");
al.add("Mukesh");
al.add("Tahir");
Collections.sort(al);
Iterator itr=al.iterator();
while(itr.hasNext()){
System.out.prin... |
What is Java Comparable interface?
| Java Comparable interface is used to order the objects of the user-defined class. This interface is found in java.lang package and contains only one method named compareTo(Object). It provides a single sorting sequence only, i.e., you can sort the elements on the basis of single data member only. For example, it may be... |
What is compareTo(Object obj) method?
| public int compareTo(Object obj): It is used to compare the current object with the specified object. It returns
-positive integer, if the current object is greater than the specified object.
-negative integer, if the current object is less than the specified object.
-zero, if the current object is equal to the sp... |
What is Java Comparator interface?
| Java Comparator interface is used to order the objects of a user-defined class.
This interface is found in java.util package and contains 2 methods compare(Object obj1,Object obj2) and equals(Object element).
It provides multiple sorting sequences, i.e., you can sort the elements on the basis of any data member, ... |
What are the Methods of Java Comparator Interface?
| Method: public int compare(Object obj1, Object obj2)
Description: It compares the first object with the second object.
Method: public boolean equals(Object obj)
Description: It is used to compare the current object with the specified object.
Method: public boolean equals(Object obj)
Description: It is us... |
Can you provide an example of Java Comparator (Non-generic Old Style)?
| Let's see the example of sorting the elements of List on the basis of age and name. In this example, we have created 4 java classes:
1.Student.java
2..AgeComparator.java
3.NameComparator.java
4.Simple.java
Student.java
This class contains three fields rollno, name and age and a parameterized constructor.
c... |
Can you provide an example of Java Comparator (Generic)?
|
Student.java
class Student{
int rollno;
String name;
int age;
Student(int rollno,String name,int age){
this.rollno=rollno;
this.name=name;
this.age=age;
}
}
AgeComparator.java
import java.util.*;
class AgeComparator implements Comparator<Student>{
public int compare(Stude... |
What is Properties class in Java? | The properties object contains key and value pair both as a string. The java.util.Properties class is the subclass of Hashtable.
It can be used to get property value based on the property key. The Properties class provides methods to get data from the properties file and store data into the properties file. Moreover... |
What is the Advantage of the properties file?
| Recompilation is not required if the information is changed from a properties file: If any information is changed from the properties file, you don't need to recompile the java class. It is used to store information which is to be changed frequently. |
What are the Constructors of the Properties class?
| Constructor:Properties()
Description: It creates an empty property list with no default values.
Constructor:Properties(Properties defaults)
Description:It creates an empty property list with the specified defaults.
|
What are the Methods of Properties class?
| Method: public void load(Reader r)
Description: It loads data from the Reader object.
Method: public void load(InputStream is)
Description: It loads data from the InputStream object
Method: public void loadFromXML(InputStream in)
Description: It is used to load all of the properties represented by the XM... |
Can you provide an example of Properties class to get information from the properties file?
| To get information from the properties file, create the properties file first.
db.properties
user=system
password=oracle
Now, let's create the java class to read the data from the properties file.
Test.java
import java.util.*;
import java.io.*;
public class Test {
public static void main(Stri... |
What are the Difference between ArrayList and Vector?
| ArrayList and Vector both implements List interface and maintains insertion order.
However, there are many differences between ArrayList and Vector classes that are given below.
1) ArrayList is not synchronized while Vector is synchronized.
2) ArrayList increments 50% of current array size if the number of eleme... |
What is Java Vector?
| Vector is like the dynamic array which can grow or shrink its size. Unlike array, we can store n-number of elements in it as there is no size limit. It is a part of Java Collection framework since Java 1.2. It is found in the java.util package and implements the List interface, so we can use all the methods of List int... |
What is the class declaration for Java Vector class?
| public class Vector<E>
extends Object<E>
implements List<E>, Cloneable, Serializable
|
What are the Constructors of the Java Vector?
| SN:1
Constructor: vector()
Description: It constructs an empty vector with the default size as 10.
SN:2
Constructor: vector(int initialCapacity)
Description: It constructs an empty vector with the specified initial capacity and with its capacity increment equal to zero.
SN:3
Constructor: vector(int initialC... |
Can you provide an example of Java Vector?
|
import java.util.*;
public class VectorExample {
public static void main(String args[]) {
//Create a vector
Vector<String> vec = new Vector<String>();
//Adding elements using add() method of List
vec.add("Tiger");
vec.add("Lion");
... |
What are the methods of Java Stack?
| SN:1
Method: add()
Description: It is used to append the specified element in the given vector.
SN:2
Method: addAll()
Description:It is used to append all of the elements in the specified collection to the end of this Vector.
SN:3
Method:addElement()
Description:It is used to append the specified com... |
What is Java Stack Class?
| In Java, Stack is a class that falls under the Collection framework that extends the Vector class. It also implements interfaces List, Collection, Iterable, Cloneable, Serializable. It represents the LIFO stack of objects. Before using the Stack class, we must import the java.util package. The stack class arranged in t... |
What are the Constructors of the Stack Class?
| The Stack class contains only the default constructor that creates an empty stack.
public Stack()
|
How to Creat a Stack?
| If we want to create a stack, first, import the java.util package and create an object of the Stack class.
Stack stk = new Stack();
Or
Stack<type> stk = new Stack<>();
|
What are the Methods of the Stack Class?
|
We can perform push, pop, peek and search operation on the stack. The Java Stack class provides mainly five methods to perform these operations. Along with this, it also provides all the methods of the Java Vector class.
Method: empty()
Modifier and Type: boolean
Description: The method checks the stack is em... |
What is Java Collection Interface?
| Collection is a group of objects, which are known as elements. It is the root interface in the collection hierarchy. This interface is basically used to pass around the collections and manipulate them where the maximum generality is desired.
|
What is Iterator in Java?
| In Java, an Iterator is one of the Java cursors. Java Iterator is an interface that is practiced in order to iterate over a collection of Java object components entirety one by one. It is free to use in the Java programming language since the Java 1.2 Collection framework. It belongs to java.util package.
Though Jav... |
What are the Advantages of Java Iterator?
|
Iterator in Java became very prevalent due to its numerous advantages. The advantages of Java Iterator are given as follows :
-The user can apply these iterators to any of the classes of the Collection framework.
-In Java Iterator, we can use both of the read and remove operations.
-If a user is working with a fo... |
What are the Disadvantages of Java Iterator? | Despite the numerous advantages, the Java Iterator has various disadvantages also. The disadvantages of the Java Iterator are given below :
-The Java Iterator only preserves the iteration in the forward direction. In simple words, the Java Iterator is a uni-directional Iterator.
-The replacement and extension of a ... |
How to use Java Iterator?
| When a user needs to use the Java Iterator, then it's compulsory for them to make an instance of the Iterator interface from the collection of objects they desire to traverse over. After that, the received Iterator maintains the trail of the components in the underlying collection to make sure that the user will traver... |
What are the methods of Java Iterator?
| The following figure perfectly displays the class diagram of the Java Iterator interface. It contains a total of four methods that are:
-hasNext()
-next()
-remove()
-forEachRemaining()
The forEachRemaining() method was added in the Java 8. Let's discuss each method in detail.
-boolean hasNext(): The method ... |
Can you provide an example of Java Iterator?
| Now it's time to execute a Java program to illustrate the advantage of the Java Iterator interface. The below code produces an ArrayList of city names. Then we initialize an iterator applying the iterator () method of the ArrayList. After that, the list is traversed to represent each element.
JavaIteratorExample.jav... |
What is Java Deque?
| A deque is a linear collection that supports insertion and deletion of elements from both the ends. The name 'deque' is an abbreviation for double-ended queue.
There are no fixed limits on the deque for the number of elements they may contain. However, this interface supports capacity restricted deques as well as th... |
What are the methods of Java Deque? | Method: add(E e)
Description: This method is used to insert a specified element into the queue represented by the deque
Method: addAll(Collection<? Extends E>c)
Description: Adds all the elements in the specified collection at the end of the deque.
Method: addFirst(E e)
Description: Inserts the specified... |
What is Java ConcurrentHashMap class? | A hash table supporting full concurrency of retrievals and high expected concurrency for updates. This class obeys the same functional specification as Hashtable and includes versions of methods corresponding to each method of Hashtable. However, even though all operations are thread-safe, retrieval operations do not e... |
What is the class declaration for Java ConcurrentHashMap class?
| public class ConcurrentHashMap<K,V>
extends AbstractMap<K,V>
implements ConcurrentMap<K,V>, Serializable
|
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.