Found 9326 Articles for Object Oriented Programming

Different methods to append a single character to a string or char array in Java

Janani Jaganathan
Updated on 25-Aug-2022 09:06:21

668 Views

Have you ever faced the situation of extending a string or char array? If you haven't yet, you might probably encounter this situation in the future. It is a common practice to append a single character to a string or char array in Java. The significant difference between a string array and a char array is that a string array is a sequence of characters, and a char array is a sequence of collection of data type char. String array runs as a single entity, whereas char array runs as a separate entity. In this blog, we will look ... Read More

Top Resources for Java Interview Questions

Janani Jaganathan
Updated on 25-Aug-2022 09:06:56

283 Views

Are you a fresher or final-year graduate looking to start your career as a Java developer? Have you already landed as a java developer and are looking to prepare for the next company? If you say "Yes" to any of these questions, then you are at the right place. In this article, you will come across the top resources and websites that will help you to prepare and do well in java programming interviews. The list includes popular online platforms and websites like Tutorialspoint, StackOverflow, DZone, etc., where you can learn frequently asked java questions in top companies' interviews and ... Read More

How to use List size() method in Java With Examples?

Mahesh Parahar
Updated on 27-May-2022 08:33:11

416 Views

The List interface extends the Collection interface and stores a sequence of elements. The List interface provides two methods to efficiently insert and remove multiple elements at an arbitrary point in the list. Unlike sets, list allows duplicate elements, and allows multiple null values if null value is allowed in the list.List interface size() can be used to get the count of elements currently present in the list. It always returns the count of currently present elements. You can check the latest size after adding/removing element(s) to the list.Syntaxint size()NotesReturns the number of elements in this list.If this list contains ... Read More

How to get sublist of List in Java?

Mahesh Parahar
Updated on 26-May-2022 13:25:38

6K+ Views

The List interface extends Collection and declares the behavior of a collection that stores a sequence of elements. User of a list has quite precise control over where an element to be inserted in the List. These elements are accessible by their index and are searchable. ArrayList is the most popular implementation of the List interface.List interface method subList() can be used to get a sublist of the list. It requires start and end index. This sublist contains the same objects as in original list and changes to sublist will also reflect in original list. In this article, we're discussing ... Read More

How to remove an element from a Java List?

Mahesh Parahar
Updated on 26-May-2022 13:25:06

4K+ Views

The List interface is a Collection and it stores a sequence of elements. ArrayList is the most popular implementation of the List interface. A list provides user has quite precise control over where an element to be inserted in the List. These elements are accessible by their index and are searchable. ArrayList is the most common implementation of List interface.Elements can be removed from a List using multiple ways.Way #1Remove an element using its index.SyntaxE remove(int index)NotesRemoves the element at the specified position in this list.Shifts any subsequent elements to the left (subtracts one from their indices).Returns the element that ... Read More

How to iterate over a list in Java?

Mahesh Parahar
Updated on 26-May-2022 13:23:51

5K+ Views

The List interface extends Collection interface and represents a collection storing a sequence of elements. User of a list has quite precise control over where an element to be inserted in the List. These elements are accessible by their index and are searchable. ArrayList is the most popular implementation of the List interface among the Java developers.There are multiple ways to iterate a Java List. Following are some of the ways −Way #1Use for/while loop to iterate a List and get element by index.for(int i= 0; i < list.size(); i++) {    System.out.println(list.get(i)); }Way #2Use foreach loop to iterate list ... Read More

How to iterate List Using Streams in Java?

Mahesh Parahar
Updated on 26-May-2022 13:23:21

17K+ Views

The List interface extends the Collection interface and stores a sequence of elements. The List interface provides two methods to efficiently insert and remove multiple elements at an arbitrary point in the list. Unlike sets, the list allows duplicate elements, and allows multiple null values if a null value is allowed in the list.You can use stream() method of the List interface which gives a stream to iterate using forEach method. In forEach method, we can use the lambda expression to iterate over all elements. The following code snippet shows the usage of streams to iterate over the list.list.stream().forEach(i -> ... Read More

How to iterate List using Iterator in Java?

Mahesh Parahar
Updated on 26-May-2022 13:22:29

458 Views

The List interface extends the Collection interface. It is a collection that stores a sequence of elements. ArrayList is the most popular implementation of the List interface. The user of a list has quite precise control over where an element to be inserted in the List. These elements are accessible by their index and are searchable.List interface provides an iterator() method which returns an Iterator to iterate the list of elements. The following code snippet shows the use of iterator.Iterator iterator = list.iterator(); while(iterator.hasNext()) {    System.out.print(iterator.next() + " "); }There is another but more flexible and powerful iterator available ... Read More

How to iterate a List using for-Each Loop in Java?

Mahesh Parahar
Updated on 26-May-2022 13:22:01

669 Views

The List interface extends Collection interface and is an important member of Java Collections Framework. List interface declares the behavior of a collection that stores a sequence of elements. The most popular implementation of List interface is ArrayList. User of a list has quite precise control over where an element to be inserted in the List. These elements are accessible by their index and are searchable.A forEach loop helps in iterating an array or collection of objects. As List contains objects, it can be easily iterated using forEach loop. Following code snippet shows how to use a forEach loop to ... Read More

How to iterate a List using for Loop in Java?

Mahesh Parahar
Updated on 26-May-2022 13:21:31

7K+ Views

The List interface extends the Collection interface and stores a sequence of elements. The List interface provides two methods to efficiently insert and remove multiple elements at an arbitrary point in the list. Unlike sets, the list allows duplicate elements and allows multiple null values if a null value is allowed in the list.To use for loop, we need the size of the collection and indexed access to its item. The list has a size() method to give the size of the list and the get() method to get an item at a particular index. The following snippet shows how ... Read More

Advertisements