Introduction to java.util Package
Tags: java, beginners, codenewbie, computerscience
Published: 2021-09-12 10:45:39

Hello all👋 I hope you are doing well. This is going to be a short introductory article about the most useful package in Java i.e., **java.util package**. 

## Let's begin...
### Let's first understand package
**What is a package?** 
<br>*In short a Java package is collection of similar type of classes.* 
<br>A Package can be defined as a collection of similar types of classes, interfaces and sub-packages in the form of directory structure. You can read more about packages in one of my article ***[here](https://dev.to/ritvikdubey27/you-must-know-this-about-java-ii-1k21)***.

### java.util
The basic utility classes required to a programmer are present in this package. *It 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).* 

**To use any class you have to import java.util package at top of the program:-**

```Java
import java.util.*;
``` 
**or**

```Java
import java.util.Class_name;
``` 

<br>To make it easy let's take an example, let's suppose you want to print date and time in your program you will need to import **java.util** package.

```Java
import java.util.Date;
//or
//import java.util.*;

public class Demo {
    public static void main(String[] args) {
        Date date = new Date();
        System.out.println("The date is : " + date);
    }
}
``` 
***You can run your code online [here](https://www.tutorialspoint.com/compile_java_online.php)***

![java.util.png](https://cdn.hashnode.com/res/hashnode/image/upload/v1631432248405/oWB1aHLjb.png)

### What is use of java.util package?

- For Java collections.
- For random number generation.
- For Calendar.
- For string parsing.
- For internationalization support by using the internationalization supported classes from java.util package **(Locale)**.

### Some important and generally used classes
Some important and generally used classes and interfaces which are present inside the java.util package are:-

- **Arrays :-** This class contains various methods for manipulating arrays.
- **ArrayList :-** This class is resizable-array implementation of the List interface.
- **Collections :-** This class consists exclusively of static methods that operate on or return collections.
- **Date :-** This class represents a specific instant in time, with millisecond precision.
- **EventObject :-** This class is the root class from which all event state objects shall be derived.
- **Formatter :-** An interpreter for printf-style format strings.
- **HashMap :-** The HashMap class Hash table based implementation of the Map interface.
- **HashSet :-** The HashSet class implements the Set interface, backed by a hash table (actually a HashMap instance).
- **HashTable :-** The HashTable class implements a hash table, which maps keys to values.
- **LinkedList :-** The LinkedList class Doubly-linked list implementation of the List and Deque interfaces.
- **Locale :-** A Locale object represents a specific geographical, political, or cultural region.
- **Objects :-** This class consists of static utility methods for operating on objects.
- **Random :-** An instance of this class is used to generate a stream of pseudorandom numbers.
- **Scanner :-** A simple text scanner which can parse primitive types and strings using regular expressions. *([Read more](https://dev.to/ritvikdubey27/scanner-class-6ba))*
- **StringTokenizer :-** The string tokenizer class allows an application to break a string into tokens.
- **Timer :-** A facility for threads to schedule tasks for future execution in a background thread.
- **TimerTask :-** A task that can be scheduled for one-time or repeated execution by a Timer.
- **TreeMap :-** The TreeMap class A Red-Black tree based NavigableMap implementation.
- **TreeSet :-** The TreeSet class A NavigableSet implementation based on a TreeMap.

#### Resources-
*[Documentation](https://docs.oracle.com/javase/8/docs/api/java/util/package-summary.html)* ||
*[Tutorial](https://www.hudatutorials.com/java/util/)* 


#### Okay so that's enough for now.
#### *Thank you for reading.*
#### *Please share your thoughts about it and correct me if I'm wrong.*
#### *I hope you liked it and found it helpful.*
#### ***Cover:- [Rajat Gour](https://twitter.com/rajatgour20)***
#### *Connect with me on [Twitter](https://twitter.com/ritvikdubey27?s=09) or [LinkedIn](https://www.linkedin.com/in/ritvik-dubey-3bbb22169)*
#### *My personal blog [blog.ritvikdubey.com](https://blog.ritvikdubey.com/)*