java util Package
java.util Package in Java
java.util package provides Java collections framework classes, internationalization support classes, a service loader, properties, random number generation, string parsing and scanning classes, base64 encoding and decoding, a bit array, and several miscellaneous utility classes. This package also contains legacy collection classes and legacy date and time classes.
What is java.util Package ?
The java.util package is a Java package like other packages in Java. Like java.lang package, Java util package also a package which contains Java collections framework classes. Assuming you mean the packages that include the class libraries like java.lang.* and java.util.*, these live in the "lib" directory under wherever your Java Runtime Environment (JRE) is installed.
What is import java.util.* in Java ?
The import is a java keyword which is used for importing a Java class or entire Java package. For example import java.util.Calendar; means you are importing a single Calendar class. If you want to import all the classes from any Java package, your import statement must be like this import java.util.*; that means you are importing entire java.util package.
What is the use of java.util Package in Java ?
The use of java.util package is as follows
- It can be use for Java collections.
- It can be use for internationalization support by using the internationalization supported classes from java.util package.
- It can be use for random number generation.
- It can be use for string parsing.
- It can be use for base64 encoding and decoding.
Collections Framework in Java
A collection sometimes called a container is simply an object that groups multiple elements into a single unit. Collections are used to store, retrieve, manipulate, and communicate aggregate data.
- A collection is the same as the intuitive, mathematical concept of a set. A set is just a group of unique items, meaning that the group contains no duplicates.
- Java Collections Framework provides a set of interfaces and classes for storing and manipulating groups of data as a single unit, a collection.
- The framework provides a convenient API to many of the abstract data types maps, sets, lists, trees, arrays, hashtables, and other collections.
- Because of their object-oriented design, the Java classes in the Collections Framework encapsulate both the data structures and the algorithms associated with these abstractions.
- With the Java Collections Framework the programmer easily define higher level data abstractions, such as stacks, queues, and thread safe collections.
java.util package contains Java Collections Framework classes as follows.
|Sl.No.||Collections Framework Class||Description|
|1||AbstractCollection||The AbstractCollection class provides a skeletal implementation of the Collection interface, to minimize the effort required to implement this interface.|
|2||AbstractList||The AbstractList class provides a skeletal implementation of the List interface to minimize the effort required to implement this interface backed by a "random access" data store (such as an array).|
|3||AbstractMap||The AbstractMap class provides a skeletal implementation of the Map interface, to minimize the effort required to implement this interface.|
|4||AbstractQueue||The AbstractQueue class provides skeletal implementations of some Queue operations.|
|5||AbstractSequentialList||The AbstractSequentialList class provides a skeletal implementation of the List interface to minimize the effort required to implement this interface backed by a "sequential access" data store (such as a linked list).|
|6||AbstractSet||The AbstractSet class provides a skeletal implementation of the Set interface to minimize the effort required to implement this interface..|
|7||ArrayDeque||The ArrayDeque class Resizable-array implementation of the Deque interface.|
|8||ArrayList||The ArrayList class Resizable-array implementation of the List interface.|
|9||Arrays||The Arrays class contains various methods for manipulating arrays (such as sorting and searching).|
|10||Collections||The Collections class consists exclusively of static methods that operate on or return collections.|
|11||EnumMap||The EnumMap class A specialized Map implementation for use with enum type keys.|
|12||EnumSet||The EnumSet class A specialized Set implementation for use with enum types.|
|13||HashMap||The HashMap class Hash table based implementation of the Map interface.|
|14||HashSet||The HashSet class implements the Set interface, backed by a hash table (actually a HashMap instance).|
|15||HashTable||The HashTable class implements a hash table, which maps keys to values.|
|16||IdentityHashMap||The IdentityHashMap class implements the Map interface with a hash table, using reference-equality in place of object-equality when comparing keys (and values).|
|17||LinkedHashMap||The LinkedHashMap class Hash table and linked list implementation of the Map interface, with predictable iteration order.|
|18||LinkedHashSet||The LinkedHashSet class Hash table and linked list implementation of the Set interface, with predictable iteration order.|
|19||LinkedList||The LinkedList class Doubly-linked list implementation of the List and Deque interfaces.|
|20||PriorityQueue||The PriorityQueue class An unbounded priority queue based on a priority heap.|
|21||TreeMap||The TreeMap class A Red-Black tree based NavigableMap implementation.|
|22||TreeSet||The TreeSet class A NavigableSet implementation based on a TreeMap.|
|23||Vector||The Vector class implements a growable array of objects.|
|24||WeakHashMap||The WeakHashMap class Hash table based implementation of the Map interface, with weak keys.|
Internationalization (I18N) Supported Classes in Java
Create application that can be adapted to different languages and regions is known as Internationalization (I18N). Which provides support for various countries, various languages and various currency formates without performing any change in the application.
Internationalization is also abbreviated as I18N because there are total 18 characters between the first letter 'I' and the last letter 'N'.
Internationalization (I18N) Supported Classes in Java as follows.
- Locale : A Java Locale class represents a specific geographical, political, or cultural region.
- Locale.Builder : Builder is used to build instances of Locale from values configured by the setters.
- ResourceBundle : Resource bundles contain locale-specific objects.
ServiceLoader Class in Java
A facility to load implementations of a service. A service is a well-known interface or class for which zero, one, or many service providers exist. A service provider (or just provider) is a class that implements or subclasses the well-known interface or class.
Properties Class in Java
The Properties class represents a persistent set of properties. The Properties can be saved to a stream or loaded from a stream. Each key and its corresponding value in the property list is a string.