Programming Articles

Page 1681 of 2547

How do we use re.finditer() method in Python regular expression?

SaiKrishna Tavva
SaiKrishna Tavva
Updated on 23-Jan-2025 19K+ Views

The re.finditer() method in Python's 're' module finds all occurrences of a specified pattern in a string. It returns an iterator containing match objects for each occurrence. This method is especially useful when you need to determine the position of each match within the input string. Following is the syntax for re.finditer() method. re.finditer(pattern,  string,  flags=0) How to Use 're.finditer()' Method Following are the steps involved in using re.finditer() method. Import the re module: You need to import the regular expression module before using it. ...

Read More

Java Program to Sort ArrayList of Custom Objects by Property

Alshifa Hasnain
Alshifa Hasnain
Updated on 22-Jan-2025 789 Views

In this article, we will learn to sort ArrayList of custom objects by property in Java. The ArrayList class extends AbstractList and implements the List interface. ArrayList supports dynamic arrays that can grow as needed. Problem Statement ArrayList is created with an initial size. When this size is exceeded, the collection is automatically enlarged. When objects are removed, the array may be shrunk. Below is a demonstration of the same − Input − The list is defined as Java Scala Python Mysql Output  − The list after sorting values: Java Mysql Python Scala ...

Read More

Java program to convert millisecond to readable string

Alshifa Hasnain
Alshifa Hasnain
Updated on 22-Jan-2025 991 Views

In this article, we will learn to convert milliseconds to readable strings in Java. Converting milliseconds into a human-readable format such as hours, minutes, seconds, and milliseconds is a common programming task, especially in time-sensitive applications. Problem Statement The challenge is to convert a given time in milliseconds into a readable string that shows hours, minutes, seconds, and remaining milliseconds. Input long millis = 5000000; Output  Hours = 1 Minutes = 23 Seconds = 20Milliseconds = 0 1 hr(s) 23 min(s) 20 sec(s) 0 ms Approaches to convert millisecond to readable string Following are the two different approaches to converting milliseconds ...

Read More

Java program to generate n distinct random numbers

Alshifa Hasnain
Alshifa Hasnain
Updated on 22-Jan-2025 1K+ Views

In this article, we will learn to generate n distinct random numbers within a specified range, ensuring that no number is repeated in Java. Generating random numbers is a common problem in various applications such as simulations, games, and testing. Problem Statement In this problem, we are given a number n, and we need to generate n unique random numbers within a defined range, ensuring that no number is repeated. The range can be specified by the user, or it can be a default range based on the problem's requirements. Input int n = 10; Output [4, 6, 9, 1, ...

Read More

Java ResultSet isAfterLast() Method with Examples

Alshifa Hasnain
Alshifa Hasnain
Updated on 20-Jan-2025 1K+ Views

The ResultSet interface in Java is used to retrieve data from a database in a tabular form. The isAfterLast() method is one of the navigation methods in the ResultSet that helps in checking the position of the cursor. Specifically, isAfterLast() checks whether the cursor is positioned after the last row of the result set. Method Definition The isAfterLast() method of the ResultSet interface is used to determine whether the cursor is after the end of the ResultSet.This method returns a boolean this value is true, if the cursor is after the end of the ResultSet else, it returns false. ...

Read More

Java Program to append a row to a JTable in Java Swing

Alshifa Hasnain
Alshifa Hasnain
Updated on 17-Jan-2025 2K+ Views

Adding rows dynamically to a JTable is a common task in Java Swing when working with user interfaces that involve tabular data. This article walks you through creating a Java Swing application that appends a new row to a JTable when the user inputs data and clicks a button. What is JTable? A JTable is a powerful Swing component for displaying and editing tabular data. By using a DefaultTableModel, we can manage the table's data dynamically, including adding or removing rows. This makes it an excellent choice for applications requiring user interaction. Approach Following are the steps to append a row ...

Read More

Java Concurrency – yield() method

Alshifa Hasnain
Alshifa Hasnain
Updated on 17-Jan-2025 1K+ Views

In this article, we will learn that concurrency in Java allows multiple threads to execute simultaneously, sharing system resources efficiently. One of the methods provided in the Thread class for managing thread execution is the yield() method. What is the yield() Method? The yield() method is a static method of the Thread class that hints to the thread scheduler that the current thread is willing to pause its execution in favor of other threads of the same or higher priority. It is part of Java's concurrency toolbox and is primarily used for fine-tuning thread execution. Syntax of yield function − ...

Read More

What is Runnable interface in Java?

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 17-Jan-2025 2K+ Views

An interface is like a reference type, similar to a class that enforces the rules that the class must implements(It is a keyword). An interface may have abstract methods i.e. methods without a definition and also constants or variables with fixed value. What is a Runnable interface in Java? If your class is intended to be executed as a thread, then you can achieve this by implementing a Runnable interface. This belongs to the java.lang package. The Runnable interface in Java is a functional interface that enables the compiled code of the class to run as a separate thread. The ...

Read More

Java Program to Initialize a List

Alshifa Hasnain
Alshifa Hasnain
Updated on 16-Jan-2025 1K+ Views

In this article, we will learn to initialize a list in Java. A list is an ordered collection that allows us to store and access elements sequentially. It contains index-based methods to insert, update, delete, and search the elements. It can also have duplicate elements. Problem Statement Given a scenario where you need to create and initialize a list in Java, the goal is to understand and implement various approaches to initialize lists effectively.  Input   Initialize an empty list and add elements − "Apple", "Banana", "Cherry" Output  ["Apple", "Banana", "Cherry"] Different Approaches Following are the different approaches to Initialize ...

Read More

Java Program to enable cell selection in a JTable

Alshifa Hasnain
Alshifa Hasnain
Updated on 15-Jan-2025 949 Views

In this article, we will learn to enable cell selection in a JTable in Java Swing. By default, JTable allows row or column selection, but enabling cell selection gives users the ability to select individual cells. This feature is useful for tasks that require precise control over table data, such as editing or copying specific values. Approach for Enabling Cell Selection in JTableThe goal is to create a JTable where users can select individual cells, rather than just rows or columns. The approach focuses on: Creating the JTable: We define a table with data ...

Read More
Showing 16801–16810 of 25,466 articles
Advertisements