java util Package - java.util Package in Java
java.util Package in Java
The 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.
Package java.util contains the collections framework, legacy collection classes, event model, date and time facilities, internationalization, and miscellaneous utility classes (a string tokenizer, a random-number generator, and a bit array).
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.
java.util Package Import Statement Example
What does import java.util.* do in Java ?
Java util ( java.util.* ) package contains collection framework . Java collections framework contains collection classes , classes related to date and time , event model , internationalization , and miscellaneous utility classes . On importing this ( java.util ) package , you can do access all these classes and methods .
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.
What is 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 in Java .
- 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.
Java Collections Framework Classes
The AbstractCollection class provides a skeletal implementation of the Collection interface, to minimize the effort required to implement this interface.
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).
The AbstractMap class provides a skeletal implementation of the Map interface, to minimize the effort required to implement this interface.
The AbstractQueue class provides skeletal implementations of some Queue operations.
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).
The AbstractSet class provides a skeletal implementation of the Set interface to minimize the effort required to implement this interface..
The ArrayDeque class Resizable-array implementation of the Deque interface.
The ArrayList class Resizable-array implementation of the List interface.
The Arrays class contains various methods for manipulating arrays (such as sorting and searching).
The Collections class consists exclusively of static methods that operate on or return collections.
The EnumMap class A specialized Map implementation for use with enum type keys.
The EnumSet class A specialized Set implementation for use with enum types.
The HashMap class Hash table based implementation of the Map interface.
The HashSet class implements the Set interface, backed by a hash table (actually a HashMap instance).
The HashTable class implements a hash table, which maps keys to values.
The IdentityHashMap class implements the Map interface with a hash table, using reference-equality in place of object-equality when comparing keys (and values).
The LinkedHashMap class Hash table and linked list implementation of the Map interface, with predictable iteration order.
The LinkedHashSet class Hash table and linked list implementation of the Set interface, with predictable iteration order.
The LinkedList class Doubly-linked list implementation of the List and Deque interfaces.
The PriorityQueue class An unbounded priority queue based on a priority heap.
The TreeMap class A Red-Black tree based NavigableMap implementation.
The TreeSet class A NavigableSet implementation based on a TreeMap.
The Vector class implements a growable array of objects.
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.