- 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 9321 Articles for Object Oriented Programming
![Mahesh Parahar](https://www.tutorialspoint.com/assets/profiles/127878/profile/60_2277600-1655382864.jpg)
1K+ Views
We can insert element between two items of an array list easily using its add() method.Syntaxvoid add(int index, E element)Inserts the specified element at the specified position in this list (optional operation). Shifts the element currently at that position (if any) and any subsequent elements to the right (adds one to their indices).Type ParameterE − The runtime type of the element.Parametersindex − Index at which the specified element is to be inserted.e − Element to be inserted to this list.ThrowsUnsupportedOperationException − If the add operation is not supported by this listClassCastException − If the class of the specified element prevents it ... Read More
![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)
329 Views
In this article, we will understand how to convert array into collection. The Collection is a framework that provides architecture to store and manipulate the group of objects. Java Collections can achieve all the operations that you perform on a data such as searching, sorting, insertion, manipulation, and deletion.Below is a demonstration of the same −Suppose our input is −Input array: [Java, Python, Scala, Shell]The desired output would be −After elements after converting the array to a list are: [Java, Python, Scala, Shell]AlgorithmStep 1 - START Step 2 - Declare a string array namely input_array and a list namely result_list. ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
2K+ Views
A string is a class in Java that stores a series of characters enclosed within double quotes and a continuous sequence of characters within that string is termed as substring. Those characters are actually String-type objects. This article aims to write Java programs to check if a string contains a substring or not. To check whether the given string contains a substring or not, we can use indexOf(), contains() and substring() methods along with conditional blocks. Java Program to Check if a String Contains a Substring We are going to use the following built-in methods in our Java programs to ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
1K+ Views
While displaying a long input string, we are sometimes required to process them in smaller units. At that time, converting that string into the InputStream will be helpful. To convert a given string into the InputStream, Java provides ByteArrayInputStream class that is used along with a built method named getBytes(). In this article, we will learn how we can use the ByteArrayInputStream class to convert a string into an InputStream with the help of example programs. Java Program to Convert a String into the InputStream This section will introduce a few concepts that will help us to understand the Java ... Read More
![AmitDiwan](https://www.tutorialspoint.com/assets/profiles/123055/profile/60_187394-1565938756.jpg)
253 Views
LinkedList is a generic class of Java Collection Framework that implements three interfaces namely List, Deque, and Queue. It provides the features of a LinkedList data structure which is a linear data structure where each element are linked with each other. There are several operations we can perform on LinkedList including appending, removing and traversing of elements. To add elements to a LinkedList Collection we can use various built-in methods such as add(), addFirst() and addLast(). We are going to explore how we can use these methods to add elements to a LinkedList. Adding elements to a LinkedList in Java ... Read More