public interface BlockingQueue<E> extends Queue <E>
Collections.sort()
method is used the elements get sorted based on the natural order that is specified in the compareTo()
method. On the other hand when Collections.sort(Comparator) method is used it sorts the objects based on compare()
method of the Comparator interface. Equals()
verifies whether the number object is equal to the object, which is passed as an argument or not.public boolean equals(Object o)
import java.lang.Integer;
public class Test {
public static void main(String args[]) {
Integer p = 5;
Integer q = 20;
Integer r =5;
Short s = 5;
System.out.println(p.equals(q));
System.out.println(p.equals(r));
System.out.println(p.equals(s));
}
}
asList()
method of Arrays class. It is a static method of Arrays class that accept the List object. The syntax of asList()
method is :Arrays.asList(item)
List_object.toArray(new String[List_object.size()])
//String array
String[] num_words = {"one", "two", "three", "four", "five"};
//Use java.util.Arrays class to convert to list
List wordList = Arrays.asList(num_words);
public static final <T> Set<T> emptySet()
. poll()
and remove()
method is used to remove head object of the Queue.empty()
. If Queue is empty then poll()
method will return null . While in similar case , remove()
method will throw NoSuchElementException . peek()
method retrieves but does not remove the head of the Queue. If queue is empty then peek()
method also returns null.Java.util.IdentityHashMap
implements Map interface and it does not make use of equals()
and hashcode()
methods to compare objects insteadIdentityHashMap uses equality operator "==
" to compare the key and value objects.IdentityHashMap
is not synchronized.Iterator.remove
is the only safe way to modify a collection during iteration;
the behavior is unspecified if the underlying collection is modified in any other way while the iteration is in progress. import java.util.*;
import java.io.*;
public class Test {
public static void main(String[] args)throws Exception{
FileReader reader=new FileReader("db.properties");
Properties p=new Properties();
p.load(reader);
System.out.println(p.getProperty("user"));
System.out.println(p.getProperty("password"));
}
} ​
Output :system
oracle
clear()
method, which will remove all the elements from the list.Collections.sort()
, the elements are sorted based on the order mention in compareTo()
.compare()
of the Comparator interface.Collections.unmodifiableList(list)
” and calling call()
, add()
or remove()
method. It should clearly throw UnsupportedOperationException.