Vivek Verma has Published 113 Articles

How to convert an Array to a List in Java program?

Vivek Verma

Vivek Verma

Updated on 27-May-2025 14:23:13

648 Views

In Java, an array is a container object that holds a similar type of data (elements), but has a fixed size. You can declare it by assigning values in curly braces or creating it using the new keyword by specifying the size. A List in Java is an interface that ... Read More

How To Check if a Triangle is Valid or Not When Sides are Given in Java?

Vivek Verma

Vivek Verma

Updated on 27-May-2025 13:37:32

9K+ Views

A Triangle is a polygon that has 3 sides, and it consists of three sides and three vertices. The sum of the three internal angles is up to 180 degrees. Below is the diagram of a triangle having three sides (a, b, and c): In a valid triangle, if ... Read More

How to iterate over a list in Java?

Vivek Verma

Vivek Verma

Updated on 26-May-2025 20:02:38

5K+ Views

In Java if you try to print a List (or any) object directly using the print statement a hash-code of the object will be printed (default behaviour). If you want to print each element of your object (such as List, Array, etc.) or perform any operation on them one by ... Read More

How to search in a List of Java object?

Vivek Verma

Vivek Verma

Updated on 26-May-2025 20:01:00

4K+ Views

A List is a sequence of elements of similar data types, and like an array, its elements are stored at specific indices, which can be accessed and searchable through the index (i.e., starting at index 0). We can search through each element in the list and retrieve its index (or ... Read More

How to remove all elements of ArrayList in Java?

Vivek Verma

Vivek Verma

Updated on 26-May-2025 19:55:35

10K+ Views

In Java, the ArrayList class provides various built-in methods to remove all or a single element from it. Once those methods are called on the ArrayList, the list will become empty (). You can verify this using the size() method; it returns 0, if the list is empty. We can ... Read More

How to iterate a List using for Loop in Java?

Vivek Verma

Vivek Verma

Updated on 26-May-2025 19:48:39

9K+ Views

To iterate over a List using a for loop, we need to know the size (which can be calculated using the size() method) of the list, so that the loop can execute an accessing element code block till the last position, which is starts from index 0. Once the loop ... Read More

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

Vivek Verma

Vivek Verma

Updated on 26-May-2025 19:48:11

816 Views

A List is an ordered collection or an interface that contains elements of similar types. Since the list is a collection object, we can iterate (or loop) a list using different control flow statements or an Iterator object. This article will discuss one way to (i.e., using forEach loop) iterate ... Read More

How to get sublist of List in Java?

Vivek Verma

Vivek Verma

Updated on 26-May-2025 19:42:36

7K+ Views

In Java, a List is an interface that stores elements of the same type. You can retrieve a sub-list from a List in Java. A sub-list is the view of a portion (or part) of the List. For example, if the given list is {a, b, c, d, e}, then ... Read More

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

Vivek Verma

Vivek Verma

Updated on 26-May-2025 19:39:42

577 Views

In Java, a List is an interface which stores a sequence of elements of similar types. Since the list contains multiple elements, we might need to know how many element the list currently have. To count the total number of elements present in a list, the List interface provides a ... Read More

How to remove an element from a Java List?

Vivek Verma

Vivek Verma

Updated on 26-May-2025 19:20:28

5K+ Views

In Java, List is an interface that stores a sequence of elements of similar types. Like an array, elements in the list are stored at a specific index starting at 0. Since we can access elements in the list through their index, and we can pass this index value to ... Read More

Previous 1 ... 6 7 8 9 10 ... 12 Next
Advertisements