0% found this document useful (0 votes)
5 views9 pages

Java.util Package Overview

Java

Uploaded by

Revanth Yadasi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views9 pages

Java.util Package Overview

Java

Uploaded by

Revanth Yadasi
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Page 1 of 9

[Link] Package Tutorial

Java - [Link] Package

The [Link] package is a standard package of Java SDK. It contains the collections framework, legacy collection
classes, event model, date and time facilities, internationalization, and miscellaneous utility classes. This
package is very useful as it provides commonly used Collections like ArrayList, HashMap, Set etc. [Link]
provides StrinTokenizer classes for String operations and similarly other utility classes for event model handlings,
date and time operations and lot more. This reference will take you through simple and practical methods
available in [Link] package.

Importing [Link] Package

Being an inbuilt package of Java, we're not required to download any external library for [Link] package and its
all classes can be imported using following syntax:

import [Link].*;

Here we've used * operator to import all classes from [Link] package and now any class can be used in the
program. In case of specific class, for example ArrayList, we can import a class using following syntax:

import [Link];

Why [Link] Package is used in Java Programs


Powered by:

[Link] package classes contains utility classes like collections frameworks, String operations utilities, Date and
Time operations utilities. Following list shows some of the categories of classes of [Link] package.
00:00
Page 2 of 9

Collections − ArrayList, HashMap, Dictionary are few of the classes of large set of Collection classes
availble in [Link] package. These classes provides commonly used operations on large data sets.

Date Time Operations − GregorianCalendar, Timezone are some of the classes of utility classes availble
in [Link] package. These classes provides commonly used operations on date and time.

String Manipulations − StringTokenizer is an important utility class availble in [Link] package. This
class provides a lot of operations to manipulate strings.

Enumerations − Enumeration class of [Link] package provides operations on set of values like
iterations, comparison etc.

Exceptions − [Link] package contains various commonly occuring exceptions like


ConcurrentModificationException, InputMismatchException etc.

Important classes in [Link] Package

Following is the list of important classes in [Link]:

ArrayDeque − This class provides resizable-array and implements the Deque interface. This class and its
iterator implement all of the optional methods of the Collection and Iterator interfaces.

ArrayList − This class provides resizable-array and implements the List interface. The ArrayList class
extends AbstractList and implements the List interface. ArrayList supports dynamic arrays that can grow
as needed.

Arrays − This class contains a static factory that allows arrays to be viewed as lists. The ArrayList class
contains various methods for manipulating arrays (such as sorting and searching).

BitSet − This class creates a special type of array that holds bit values. The BitSet array can increase in
size as needed. This makes it similar to a vector of bits. This is a legacy class but it has been completely
re-engineered in Java 2, version 1.4. The Java BitSet class implements a vector of bits that grows as
needed. Powered by:

Calendar − This class is an abstract class that provides methods for converting between a specific
instant in time and a set of calendar fields such as YEAR, MONTH, DAY_OF_MONTH, HOUR, and so on,
and for manipulating the calendar fields, such as getting the date of the next week.
00:00
Page 3 of 9
Collections − This class consists exclusively of static methods that operate on or return collections.

Currency − This class represents a currency. The Currency class is designed so that there's never more
than one Currency instance for any given currency, this is the reason behind no public constructor.

Date − This class represents a specific instant in time, with millisecond precision.

Dictionary − This class is the abstract parent of any class, such as Hashtable, which maps keys to
values.

EnumMap − This class is a specialized Map implementation for use with enum keys. All of the keys in an
enum map must come from a single enum type that is specified, explicitly or implicitly, when the map is
created.

EnumSet − This class is a specialized Set implementation for use with enum keys. All of the keys in an
enum set must come from a single enum type that is specified, explicitly or implicitly, when the set is
created.

Formatter − This class provides support for layout justification and alignment, common formats for
numeric, string, and date/time data, and locale-specific output.

GregorianCalendar − This class is a concrete subclass of Calendar and provides the standard calendar
system used by most of the world. It is a hybrid calendar that supports both the Julian and Gregorian
calendar systems with the support of a single discontinuity, which corresponds by default to the
Gregorian date when the Gregorian calendar was instituted.

HashMap − This class is the Hash table based implementation of the Map interface.

HashSet − This class implements the Set interface, backed by a hash table.

HashTable − This class implements a hashtable, which maps keys to values.

IdentityHashMap − This class implements the Map interface with a hash table, using reference-equality
in place of object-equality when comparing keys (and values).

LinkedHashMap − This class is Hash table and Linked list implementation of the Map interface, with
predictable iteration order.

LinkedHashSet − This class is Hash table and Linked list implementation of the Set interface, with
predictable iteration order.

LinkedList − This class operations perform we can expect for a doubly-linked list. Operations that index
into the list will traverse the list from the beginning or the end, whichever is closer to the specified index.

ListResourceBundle − This class is an abstract subclass of ResourceBundle that manages resources for
a locale in a convenient and easy to use list.

Locale − This class object represents a specific geographical, political, or cultural region.

Observable − This class represents an observable object, or "data" in the model-view paradigm. The class
can be subclassed to represent an object that the application wants to have observed.

PriorityQueue − This class is an unbounded priority queue based on a priority heap. The elements of the
priority queue are ordered according to their natural ordering, or by a Comparator provided at queue
Powered by:
construction time, depending on which constructor is used.

Properties
Home − This class is a
Whiteboard classCompilers
Online which represents a persistent
Practice set of properties.
Articles Tools The Properties can be
saved to a stream or loaded from a stream.

PropertyPermission − This class is a class for property permissions.


Chapters 00:00 Categories
Page 4 of 9
PropertyResourceBundle − This class is a concrete subclass of ResourceBundle that manages resources
for a locale using a set of static strings from a property file.

Random − This class instance is used to generate a stream of pseudorandom numbers. The class uses a
48-bit seed, which is modified using a linear congruential formula.

ResourceBundle − This class contain locale-specific objects. The class allows you to write programs that
can be easily localized, or translated, into different languages.

[Link] − This class collaborates with the factory methods for loading resource
bundles.

Scanner − This class is a simple text scanner which can parse primitive types and strings using regular
expressions.

ServiceLoader − This class is a simple service-provider loading facility. Service loaders always execute in
the security context of the [Link] system code should typically invoke the methods in this class,
and the methods of the iterators which they return, from within a privileged security context.

SimpleTimeZone − This class is a concrete subclass of TimeZone that represents a time zone for use
with a Gregorian calendar.

Stack − Stack is a subclass of Vector that implements a standard last-in, first-out stack. Stack only
defines the default constructor, which creates an empty stack. Stack includes all the methods defined by
Vector, and adds several of its own.

StringTokenizer − This class allows an application to break a string into tokens. This class is a legacy
class that is retained for compatibility reasons although its use is discouraged in new code.

Timer − This class provides facility for threads to schedule tasks for future execution in a background
thread.

TimerTask − This class represents a task that can be scheduled for one-time or repeated execution by a
Timer.

TimeZone − This class represents a time zone offset, and also figures out daylight savings.

TreeMap − This class is the Red-Black tree based implementation of the Map interface. The TreeMap
class guarantees that the Map will be in ascending key order.

TreeSet − This class implements the Set interface. The TreeSet class guarantees that the Set will be in
ascending key order and backed by a TreeSet.

UUID − This class class represents an immutable universally unique identifier (UUID). There are four
different basic types of UUIDs: time-based, DCE security, name-based, and randomly generated UUIDs.

Vector − Vector implements a dynamic array. The Vector class implements a growable array of objects.
Similar to an Array, it contains components that can be accessed using an integer index.

Examples of [Link] Package


Powered
Practice the following examples to learn the concept and usage by:
of [Link] package clasess.

Example of [Link]

The following program illustrates several of the methods supported


00:00 by ArrayList −
Page 5 of 9

package [Link];

import [Link];

public class ArrayListDemo {

public static void main(String args[]) {


// create an array list
ArrayList al = new ArrayList();
[Link]("Initial size of al: " + [Link]());

// add elements to the array list


[Link]("C");
[Link]("A");
[Link]("E");
[Link]("B");
[Link]("D");
[Link]("F");
[Link](1, "A2");
[Link]("Size of al after additions: " + [Link]());

// display the array list


[Link]("Contents of al: " + al);

// Remove elements from the array list


[Link]("F");
[Link](2);
[Link]("Size of al after deletions: " + [Link]());
[Link]("Contents of al: " + al);
}
}

This will produce the following result −

Output

Powered by:
Initial size of al: 0
Size of al after additions: 7
Contents of al: [C, A2, A, E, B, D, F]
00:00
Page 6 of 9
Size of al after deletions: 5
Contents of al: [C, A2, E, B, D]

Example of [Link]

This Java example demonstrates the from() method of Date class to get Date instance of current time.

package [Link];

import [Link];

// Import the Date package


import [Link];

// Main public class


public class DateDemo {
public static void main(String[] args) {

// create a date of current time


Date date = [Link]([Link]());

// print the date instance


[Link]("Date: " + [Link]());
}
}

Output

Let us compile and run the above program, this will produce the following result −

Date: Mon Apr 01 10:20:08 IST 2024

Example of [Link]

The following example shows the usage of Java Random doubles() method. Firstly, we've created a Random
Powered by:
object and then using doubles() we retrieved a stream of random double values and printed first value.

00:00
Page 7 of 9

package [Link];

import [Link];
import [Link];

public class RandomDemo {


public static void main( String args[] ) {

// create random object


DoubleStream randomNoStream = new Random().doubles();
// print a random double value
[Link](1).forEach( i -> [Link](i));
}
}

Output

Let us compile and run the above program, this will produce the following result.

0.5129590222446587

When [Link] Package is Used?

Whenever we need to manipulate collections, Strings, perform event handling etc, we can rely on utility classes
present in [Link] package. This reference has been prepared for the beginners to help them understand the
Powered
basic functionality related to all the methods available in [Link] by:
package.

Prerequisites

00:00
Page 8 of 9
Before you start doing practice with various types of examples given in this reference, I'm making an assumption
that you are already aware of basic Java Programming.

TOP TUTORIALS TRENDING TECHNOLOGIES

Python Tutorial Cloud Computing Tutorial

Java Tutorial Amazon Web Services Tutorial

C++ Tutorial Microsoft Azure Tutorial

C Programming Tutorial Git Tutorial

C# Tutorial Ethical Hacking Tutorial

PHP Tutorial Docker Tutorial

R Tutorial Kubernetes Tutorial

HTML Tutorial DSA Tutorial

CSS Tutorial Spring Boot Tutorial

JavaScript Tutorial SDLC Tutorial

SQL Tutorial Unix Tutorial

CERTIFICATIONS COMPILERS & EDITORS

Business Analytics Certification Online Java Compiler

Java & Spring Boot Advanced Certification Online Python Compiler

Data Science Advanced Certification Online Go Compiler

Cloud Computing And DevOps Online C Compiler

Advanced Certification In Business Analytics Online C++ Compiler

Artificial Intelligence And Machine Learning Online C# Compiler

DevOps Certification Online PHP Compiler

Game Development Certification Online MATLAB Compiler

Front-End Developer Certification Online Bash Terminal

AWS Certification Training Online SQL Compiler

Python Programming Certification Online Html Editor

ABOUT US | OUR TEAM | CAREERS | JOBS | CONTACT US | TERMS OF USE | PRIVACY POLICY |

REFUND POLICY | COOKIES POLICY | FAQ'S

Powered by:

00:00
Page 9 of 9

Tutorials Point is a leading Ed Tech company striving to provide the best learning material on technical and non-
technical subjects.

© Copyright 2025. All Rights Reserved.

Powered by:

00:00

Common questions

Powered by AI

The java.util package supports collection framework operations by providing a range of classes designed to store and manipulate groups of objects. Key classes include ArrayList, which provides resizable arrays; HashMap and HashSet, which are based on hash table data structures for efficient storage and retrieval of key-value pairs; and LinkedList, which implements a doubly-linked list to allow for dynamic data management. These classes facilitate complex data operations, such as sorting, searching, and iteration, which are essential for robust and performance-oriented applications .

The java.util.ListResourceBundle class is used for managing resource bundles that comprise locale-specific objects, typically used for localizing applications. Its main advantage is providing an easy-to-use list-based structure to access resources consistently across different locales. In a multilingual application scenario, ListResourceBundle can be employed to manage language and regional settings for UI text, error messages, and formatting rules. By structuring resources into list compartments, the application can efficiently switch languages or format styles based on user preferences, greatly improving usability in global markets .

The java.util.GregorianCalendar class integrates the Julian and Gregorian calendar systems by implementing a hybrid approach that supports a single discontinuity. This method allows seamless transition at the point when the Gregorian calendar was historically instituted. This integration is crucial for ensuring historical accuracy in date calculations and conversions across different calendar systems. Such functionality is essential for astronomical calculations, historical research, and applications that require precise date manipulation through centuries spanning different calendar regimes .

The java.util.concurrent package offers advantages over standard collection and utility classes due to its specialized design for concurrent execution. It includes thread-safe data structures like ConcurrentHashMap, CopyOnWriteArrayList, and BlockingQueue, which help avoid common pitfalls like synchronization issues and deadlocks traditionally managed through locks. These classes enhance multi-threaded performance by optimizing methods for concurrent access, facilitating asynchronous task execution, and reducing the complexity of managing thread interactions, thus leading to more responsive applications .

The java.util.Observable class plays a fundamental role in the model-view paradigm by acting as the data model that notifies observer objects about changes. It enables observers to synchronize their state with the observed model, which is vital for maintaining consistency across UI components in applications. A proper implementation scenario could be a GUI application where a data object notifies multiple views of changes, thereby ensuring the UI reflects the current state of the underlying data model. This promotes decoupling between the data logic and UI rendering, enhancing maintainability and scalability of the code .

The java.util.EnumSet class is a specialized implementation of the Set interface tailored for use with enum keys, ensuring all keys belong to a single enum type. Its efficient representation, using bit vector operations, allows rapid set operations compared to traditional sets. Developers might prefer EnumSet over traditional sets due to its high performance in scenarios with fixed ranges of enum types, such as handling states or conditions that are naturally enumerated. This class enhances memory efficiency and computational speed, especially in applications with frequent set operations .

The significance of the java.util.Random class lies in its ability to generate a sequence of pseudorandom numbers, which are crucial for simulations, games, and random sampling in statistics. It uses a linear congruential formula to produce these numbers, ensuring efficient and varied number generation. Developers can utilize this class to generate random values across various data types, including integers and doubles, which support diverse application needs such as cryptographic algorithms, randomized algorithms, and test data generation .

The java.util.Locale class is pivotal in internationalization and localization of Java applications as it represents a specific locale, providing cultural, geographical, and political environment relevant settings. This class allows applications to adapt to different languages and regional settings by specifying locale-specific text, numbers, dates, and currency formats. It helps developers build applications that can seamlessly switch between locales, enhancing their global usability and customer experience .

The java.util.Scanner class facilitates text parsing by providing a simple syntax for scanning and parsing primitive types and strings using regular expressions. It allows easy iteration through input data and extraction of formatted input, which simplifies user input processing and validation. Compared to traditional input methods, Scanner offers benefits such as built-in regex support, tokenization capabilities, and the ability to parse multiple data types in a single code construct, making it a versatile tool for developing applications that require dynamic user interactions .

The java.util.Timer class facilitates time-based operations by allowing threads to schedule tasks for future execution as one-time tasks or repeated tasks at a fixed rate or fixed delay. Potential use cases include scheduling reminders, running periodic maintenance tasks, or performing background operations like database cleanup at specific intervals. This class's flexibility in scheduling logic makes it suitable for applications requiring timing services .

You might also like