- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Found 2616 Articles for Java
![Mahesh Parahar](https://www.tutorialspoint.com/assets/profiles/127878/profile/60_2277600-1655382864.jpg)
13K+ Views
SolutionYes, We can insert null values to a list easily using its add() method. In case of List implementation does not support null then it will throw NullPointerException.Syntaxboolean add(E e)Appends the specified element to the end of this list.Type ParameterE − The runtime type of the element.Parameterse − Element to be appended to this listReturnsIt returns true.ThrowsUnsupportedOperationException − If the add operation is not supported by this listClassCastException − If the class of the specified element prevents it from being added to this listNullPointerException − If the specified element is null and this list does not permit null elementsIllegalArgumentException − If some ... Read More
![Mahesh Parahar](https://www.tutorialspoint.com/assets/profiles/127878/profile/60_2277600-1655382864.jpg)
703 Views
SolutionWe can clear a list easily using its clear() method.Syntaxvoid clear()Removes all the elements of the list.ThrowsUnsupportedOperationException − If the clear operation is not supported by this listExampleThe following example shows how to clear elements from the list using the clear() method.package com.tutorialspoint; import java.util.ArrayList; import java.util.List; public class CollectionsDemo { public static void main(String[] args) { // Create a list object List list = new ArrayList(); // add elements to the list list.add(1); list.add(2); list.add(3); ... Read More
![Mahesh Parahar](https://www.tutorialspoint.com/assets/profiles/127878/profile/60_2277600-1655382864.jpg)
672 Views
SolutionWe can add element to an array list easily using its add() method.Syntaxboolean add(E e)Appends the specified element to the end of this list.Type ParameterE − The runtime type of the element to be added.Parameterse − Element to be appended to this listReturnsIt returns true.ThrowsUnsupportedOperationException − If the add operation is not supported by this listClassCastException − If the class of the specified element prevents it from being added to this listNullPointerException − If the specified element is null and this list does not permit null elementsIllegalArgumentException − If some property of this element prevents it from being added to ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
2K+ Views
In this article, we will understand how to convert the local Time to GMT. Java does not have a built-in Date class, but we can import the java.time package to work with the date and time API. The package includes many date and time classes.Below is a demonstration of the same −Suppose our input is −The local time is: Fri Mar 18 00:01:54 IST 2022The desired output would be −The time in Gmt is: 17/03/2022 18:31:54AlgorithmStep 1 - START Step 2 - Declare an object of LocalDateTime namely date. Step 3 - Define the values. Step 4 - Define different ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
440 Views
In this article, we will understand how to display time in different country’s format. Java does not have a built-in Date class, but we can import the java.time package to work with the date and time API. The package includes many date and time classes.Below is a demonstration of the same −Suppose our input is −Run the programThe desired output would be −The England Format is: Friday, 18 March 2022 The Italian Format is: venerdì, 18 marzo 2022AlgorithmStep 1 - START Step 2 - Declare an object of LocalDateTime namely date. Step 3 - Define the values. Step 4 - ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
275 Views
In this article, we will understand how to display dates of calendar year in different format. Java does not have a built-in Date class, but we can import the java.time package to work with the date and time API. The package includes many date and time classes.Below is a demonstration of the same −Suppose our input is −Run the programThe desired output would be −The first date format is:2022-03-17T23:37:37.623304800 The second date format is:17/03/2022 The third date format is:Thursday, 17 Mar 2022AlgorithmStep 1 - START Step 2 - Declare an object of LocalDateTime namely date. Step 3 - Define the ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
2K+ Views
In this article, we will understand how to iterate over ArrayList using lambda expression. The ArrayList class is a resizable array, which can be found in the java.util package. The difference between a built-in array and an ArrayList in Java, is that the size of an array cannot be modified.Below is a demonstration of the same −Suppose our input is −Run the programThe desired output would be −The list is defined as: Java Python Scala Mysql RedshiftAlgorithmStep 1 - START Step 2 - Declare namely Step 3 - Define the values. Step 4 - Create an ArrayList, and iterate over ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
4K+ Views
In this article, we will understand how to pass ArrayList as the function argument. The ArrayList class is a resizable array, which can be found in the java.util package. The difference between a built-in array and an ArrayList in Java, is that the size of an array cannot be modified.Below is a demonstration of the same −Suppose our input is −Run the programThe desired output would be −The list is defined as: Java Python Scala Mysql RedshiftAlgorithmStep 1 - START Step 2 - Declare namely Step 3 - Define the values. Step 4 - Create an ArrayList, and iterate over ... Read More