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

Use List Size Method in Java with Examples

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

591 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

Remove 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

Calculate Volume of Prism in Java

Vivek Verma
Updated on 26-May-2025 19:09:12

1K+ Views

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

Override Start Method in Java

Vivek Verma
Updated on 26-May-2025 19:06:03

3K+ Views

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

How Not to Match a Character After Repetition in Python Regex

Nikitasha Shrivastava
Updated on 26-May-2025 18:44:05

403 Views

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

Python Regular Expression Syntax Explained Simply

Nikitasha Shrivastava
Updated on 26-May-2025 18:36:30

119 Views

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

C++ Program to Represent Graph Using 2D Arrays

Ravi Ranjan
Updated on 26-May-2025 18:32:31

2K+ Views

The graph can be represented using various ways. One of the technique is to use a 2D array, also known as adjacency matrix. The adjacency matrix is a square matrix of size V x V to represent a finite graph data structure using a 2D array, where V is the number of nodes/vertex of the graph. In an undirected non-weighted graph, if there is an edge between vertex i and vertex j, the value at matrix[i][j] is 1 and if no edge exists, the value is 0. In this article, our task is to represent the graph using 2D arrays. ... Read More

Generate Random Directed Acyclic Graph (DAC) in C++

Ravi Ranjan
Updated on 26-May-2025 18:29:29

680 Views

A Directed Acyclic Graph or DAG is a directed graph (a graph where each edge has a direction) that has no cycles present i.e. if we traverse along the direction of the edges then no closed loops are formed along any path. A DAG is always topologically ordered, i.e. for each edge in the graph, the start vertex of the edge(u) occurs earlier in the sequence than the ending vertex(v) of the edge i.e.(u {B C} B -> {Isolated Vertex} C -> {Isolated Vertex} D -> {B E} E -> {C} Steps to Generate Random Directed Acyclic Graph The ... Read More

Compare Regular Expressions in Perl and Python

Nikitasha Shrivastava
Updated on 26-May-2025 18:21:40

375 Views

This article will discuss how to compare regular expressions in Perl and Python. Regular expressions, or regex, are patterns used to match strings. Both Perl and Python support regex, but they have some differences in syntax and usage. For example, you write a regular expression like this in Perl - $text =~ /pattern/ But you write it like this in Python - re.search('pattern', text) So in the below section of this article will show the similarities and differences between Perl and Python regex with simple examples - ... Read More

Advertisements