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 remove all the elements of an ArrayList in Java: Using clear() Method of List Interface Using removeAll() Method Removing all ArrayList Elements using clear() Method The clear() method of the List interface removes (deletes) all the elements from a list. ... Read More
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 reaches at the last index of the list, it will stop executing and exit. Here are a few examples of how to iterate over a list using a for loop: Iterate a List using For Loop A for-loop is a "control flow statement " which is ... Read More
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
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
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
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
A Prism refers to a three-dimensional solid object which has two identical ends. A prism has two faces, which are: Top and Bottom face. Lateral face Both top and bottom faces are called bases which are identical to each other. All lateral faces are also identical to each other which belong to the class of parallelograms. When the base of the prism is triangular in shape that prism is called a Triangular prism. Similarly, when the base of a prism is rectangular in shape it is called a Rectangular prism. ... Read More
Yes! we can override the start() method of the Thread class in Java. But, if we do so, we must call it using super.start(), which will create a new thread; otherwise, no new thread will be created, and the run() method will not execute in parallel for the other threads. Overriding the start() Method In Java, the start() method is used to begin (start) the execution of a new Thread. When this method is called, it invokes the run() method, which executes in parallel with other threads. Example In the following example, we override the start() method within the subclass of ... Read More
Regular expression, or regex, is a useful tool in Python that helps identifying and processing of text patterns. It helps you cut, edit and check text in different ways. In this article, we will talk about how not to match a character after repetition in regex and look at five different examples. We will provide you a clear explanation to help you understand how each one works. All of the examples we will create in this article, we will use the re.findall() method, which is a built-in method of Python's re module. Let us know about this function first - ... Read More
This article explains how to work with Regular Expressions (RegEx) in Python using the "re" module. RegEx is a sequence of characters that defines a search pattern. Below are different ways to use RegEx in Python. These are some of the essential methods in Python's re module that help with pattern matching, searching, replacing, and extracting data efficiently. Using the re.match() method Using the re.findall() method Using the re.search() method Using the re.sub() and re.subn() methods Using the re.split() method Using re.match() Method The re.match() method checks if a string matches a given pattern at the ... Read More
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP