22.16 Commonly Used Libraries (e.g., java.util, java.time)
Commonly Used Libraries (e.g., java.util, java.time)
Overview
Java provides a rich set of libraries for various functionalities, such as collections, date and time manipulation, and more.
Topics
- java.util (Collections, Random, Scanner)
- java.time (LocalDate, LocalTime, DateTimeFormatter)
- java.math (BigInteger, BigDecimal)
Examples
java.util
List<String> list = Arrays.asList("A", "B", "C");
Collections.shuffle(list);
System.out.println(list);
Random random = new Random();
System.out.println(random.nextInt(100));
java.time
LocalDate date = LocalDate.now();
LocalTime time = LocalTime.now();
System.out.println("Date: " + date + ", Time: " + time);
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd-MM-yyyy");
System.out.println(date.format(formatter));
java.math
BigInteger bigInt = new BigInteger("12345678901234567890");
BigDecimal bigDec = new BigDecimal("12345.6789");
System.out.println(bigInt.add(new BigInteger("10")));
System.out.println(bigDec.multiply(new BigDecimal("2")));