- 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
6K+ Views
Java List provides a method indexOf() which can be used to get the location of an element in the list and contains() method to check if object is present or not.indexOf() methodint indexOf(Object o)Returns the index of the first occurrence of the specified element in this list, or -1 if ... Read More
Mahesh Parahar
522 Views
We can create a shallow copy of a list easily using addAll() method of List interface.Syntaxboolean addAll(Collection>? extends E> c)Appends all of the elements in the specified collection to the end of this list, in the order that they are returned by the specified collection's iterator.Type ParameterE − The runtime ... Read More
Mahesh Parahar
212 Views
We can utilize listIterator() method of List interface, which allows element insertion and replacement, and bidirectional access in addition to the normal operations that the Iterator interface provides.SyntaxListIterator listIterator()Returns a list iterator over the elements in this list (in proper sequence).ExampleFollowing is the example showing the usage of listIterator() method ... Read More
Mahesh Parahar
16K+ Views
indexOf() method of List is used to get the location of an element in the list.int 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 ... Read More
Mahesh Parahar
980 Views
indexOf() method of List can be used to get the location of an element in the list.int 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 ... Read More
Mahesh Parahar
589 Views
We can utilize Arrays.asList() method to get a List of specified elements in a single statement.Syntaxpublic static List asList(T... a)Returns a fixed-size list backed by the specified array. (Changes to the returned list "write through" to the array.)Type ParameterT − The runtime type of the array.Parametersa − The array ... Read More
Mahesh Parahar
5K+ Views
A List of elements can be created using multiple ways.Way #1Create a List without specifying the type of elements it can holds. Compiler will throw warning message for it.List list = new ArrayList();Create a List and specify the type of elements it can holds.Way #2List list = new ArrayList();Way #3Create ... Read More
Mahesh Parahar
158 Views
We can create a list from a set using its constructor.List list = new ArrayList(set);ExampleFollowing is the example showing the conversion of set to list −package com.tutorialspoint; import java.util.ArrayList; import java.util.HashSet; import java.util.List; import java.util.Set; public class CollectionsDemo { public static void main(String[] args) { ... Read More
Mahesh Parahar
554 Views
An element can be copied to another List using streams easily.Use Streams to copy selective elements.List copyOfList = list.stream().filter(i -> i % 2 == 0).collect(Collectors.toList());ExampleFollowing is the example to copy only even numbers from a list −package com.tutorialspoint; import java.util.Arrays; import java.util.List; import java.util.stream.Collectors; public class CollectionsDemo { ... Read More
Mahesh Parahar
5K+ 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
To Continue Learning Please Login
Login with Google