Uncategorized
List interface
In Java, the List interface is an ordered collection that allows us to store and access elements sequentially. It extends the Collection interface.
Classes that Implement List:
- Vector
- Stack
How to use List?
In Java, we must import java.util.List package in order to use List.
List<String> list1 = new ArrayList<>();
Methods of List:
- add() - adds an element to a list
- addAll() - adds all elements of one list to another
- get() - helps to randomly access elements from lists
- iterator() - returns iterator object that can be used to sequentially access elements of lists
- set() - changes elements of lists
- remove() - removes an element from the list
- removeAll() - removes all the elements from the list
- clear() - removes all the elements from the list (more efficient than removeAll())
- size() - returns the length of lists
- toArray() - converts a list into an array
- contains() - returns true if a list contains specified element.
Related Posts
- Design a combinational circuit with four inputs and four outputs that converts a 4bit binary number into the equivalent 4bit Gray code.
- Design a combinational circuit that accepts a 2-bit number and generates an output binary number equal to the square of the input number.
- Collection Framework
- Design a combinational circuit with four input lines that represent a decimal digit in BCD and four output lines that generate the 9’s complement of the input digit.
- List interface
- Set Interface
Post a Comment
Post a Comment