java4all@1986 java. Powered by Blogger.

>> Saturday, June 25, 2011

71.What Are the different Collection Views That Maps Provide?
A)
.Maps Provide Three Collection Views.

    Key Set - allow a map's contents to be viewed as a set of keys.
    Values Collection - allow a map's contents to be viewed as a set of values.
    Entry Set - allow a map's contents to be viewed as a set of key-value mappings.


72.What is a KeySet View ?
A).
KeySet is a set returned by the keySet() method of the Map Interface, It is a set that contains all the keys present in the Map.

73.What is a Values Collection View ?
A).
Values Collection View is a collection returned by the values() method of the Map Interface, It contains all the objects present as values in the map.

74.What is an EntrySet View ?
A).
Entry Set view is a set that is returned by the entrySet() method in the map and contains Objects of type Map. Entry each of which has both Key and Value.

75.How do you sort an ArrayList (or any list) of user-defined objects ?
A)
.Create an implementation of the java.lang.Comparable interface that knows how to order your objects and pass it to java.util.Collections.sort(List, Comparator).

76.What is the Comparable interface ?
A)
.The Comparable interface is used to sort collections and arrays of objects using the Collections.sort() and java.utils.Arrays.sort() methods respectively. The objects of the class implementing the Comparable interface can be ordered.

The Comparable interface in the generic form is written as follows:

    interface Comparable<T>

where T is the name of the type parameter.

All classes implementing the Comparable interface must implement the compareTo() method that has the return type as an integer. The signature of the compareTo() method is as follows:

      int i = object1.compareTo(object2)

    If object1 < object2: The value of i returned will be negative.
    If object1 > object2: The value of i returned will be positive.
    If object1 = object2: The value of i returned will be zero.


77.What are the differences between the Comparable and Comparator interfaces ?
A)
.Comparable     Comparator

It uses the compareTo() method.

int objectOne.compareTo(objectTwo).
    t uses the compare() method.

int compare(ObjOne, ObjTwo)
It is necessary to modify the class whose instance is going to be sorted.     A separate class can be created in order to sort the instances.
Only one sort sequence can be created.     Many sort sequences can be created.
It is frequently used by the API classes.     It used by third-party classes to sort instances.

0 comments:

Post a Comment

FaceBook Login

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

HTML/JAVASCRIPT

Total Pageviews

STATCOUNTER

  © Blogger template Simple n' Sweet by Ourblogtemplates.com 2009

Back to TOP