- 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
Mahesh Parahar has Published 255 Articles
Mahesh Parahar
10K+ Views
Elements can be checked from a list using indexOf() or contains() methods.Syntax - indexOf() methodint indexOf(Object o)Returns the index of the first occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the lowest index i such that (o==null ... Read More
Mahesh Parahar
6K+ Views
Java list size is dynamic. It increases automatically whenever you add an element to it and this operation exceeds the initial capacity. You can define the initial capacity at the time of list creation so that it allocates memory after initial capacity exhausts.List list = new ArrayList(10);But please don't use ... Read More
Mahesh Parahar
3K+ Views
List provides a method size() to get the count of elements currently present in the list. To get size of each list, we can use iterate through each item as list and add their sizes to get the count of all elements present in the list of lists. In this ... Read More
Mahesh Parahar
4K+ Views
The List provides removeAll() method to remove all elements of a list that are part of the collection provided.boolean removeAll(Collection c)Parametersc − Collection containing elements to be removed from this list.ReturnsTrue if this list changed as a result of the callThrowsUnsupportedOperationException − If the removeAll operation is not supported by ... Read More
Mahesh Parahar
243 Views
Streams can be used to search an item within list.Student student2 = list.stream().filter(s -> {return s.getRollNo() == rollNo);}).findAny().orElse(null);In this example, we're searching a student by roll number.ExampleFollowing is the example showing the usage of streams to search an item in a list −package com.tutorialspoint; import java.util.ArrayList; import java.util.List; ... Read More
Mahesh Parahar
3K+ Views
Java List provides a method lastIndexOf() which can be used to get the last location of an element in the list.int lastIndexOf(Object o)Returns the index of the last occurrence of the specified element in this list, or -1 if this list does not contain the element. More formally, returns the ... Read More
Mahesh Parahar
1K+ Views
You can check all elements of a list to be same using streams easily in two steps −Get the first element.String firstItem = list.get(0);Iterate the list using streams and use allMatch() method to compare all elements with the first element.boolean result = list.stream().allMatch(i -> i.equals(firstItem));ExampleFollowing is the example showing the ... Read More
Mahesh Parahar
168 Views
The List provides two methods to convert a List into Array.Way #1Object[] toArray()Returns an array containing all of the elements in this list in proper sequence (from first to last element).Way #2 T[] toArray(T[] a)Returns an array containing all of the elements in this list in proper sequence (from first ... Read More
Mahesh Parahar
522 Views
An ArrayList provides two methods to convert it into Array.Way #1Object[] toArray()Returns an array containing all of the elements in this list in proper sequence (from first to last element).Way #2 T[] toArray(T[] a)Returns an array containing all of the elements in this list in proper sequence (from first to ... Read More
To Continue Learning Please Login
Login with Google