Found 7442 Articles for Java

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

842 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

406 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

Difference between Groovy and Java

Aishwarya Naglot
Updated on 11-Nov-2024 15:23:48

1K+ Views

Programmers have been using scripting languages for quite some time. When it comes to Linux and Unix computers, scripting languages were mostly utilised for things like scripting tasks that automate platform customizations, software installations, and one-shot command line jobs with bash scripts. Groovy is an authentically creative language that runs on the same virtual machine as Java. Hence, it can interact with Java in a way that is both efficient and effective. Despite the fact that Java is one of the most popular and commonly used programming languages for producing content for the web, certain activities, such as file handling ... Read More

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

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

588 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 method named size(). The List size() Method The size() method of List interface is used to retrieve size of the current List. The size refers to total number of items currently the list holds. For example, a list have {1, 2, 3}, then the size of the list will be ... Read More

How to get sublist of List in Java?

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 the possible sub-lists can be {a, b}, {a, b, c}, {b, c, d}, {d, e}, etc. The List interface in Java provides a built-in method named subList(), which returns a sub-list from the given List. We just need to specify the range of extraction. Sublist from a List using the ... Read More

How to remove an element from a Java List?

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 the remove() method (i.e., a basic method for removing elements), which will remove the element at the specified index. We can remove an element from the List in Java: Using remove() Method of List Interface Using remove(object) Method ... Read More

How to iterate over a list in Java?

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 one, you need to iterate through it. Java provides various ways to iterate through objects. Following are different approaches to iterate through a List object: Using For Loop Using While Loop Using Iterator Object Iterate over ... Read More

How to iterate List Using Streams in Java?

Vivek Verma
Updated on 06-Jun-2025 10:49:25

22K+ Views

In Java, a List is an interface that stores a sequence of elements of similar type. Java provides various ways to iterate over a list, such as using a for loop, forEach loop, iterator object, stream, or forEach() method with a lambda expression. What is Stream in Java? In Java, a Stream is an interface, which represents a sequence of elements (or objects) supporting sequential and parallel aggregate operations. These operations can be used to produce the desired result. The Stream interface provides a method named stream(), which is used to create a sequential stream from the current collection (or ... Read More

How to iterate List using Iterator in Java?

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

626 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?

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

819 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 over a list: Iterate over a List Using forEach Loop A forEach loop is a control flow statement that helps to iterate (or loop through) over a collections object. As the List is an ordered collection, it can be easily iterated using a forEach loop or any other control flow ... Read More

Advertisements