Java Articles

Page 175 of 450

Java Program to get maximum value with Comparator

Alshifa Hasnain
Alshifa Hasnain
Updated on 26-Dec-2024 942 Views

In Java, the Comparator interface is used to define a custom ordering for objects in various Collections. This can be particularly useful when you need to find the maximum or minimum element based on specific criteria rather than natural ordering. One common use case is finding the maximum value in a collection using a comparator. Java provides the Collections utility class, which includes the max() and min() methods that accept a comparator to perform customized comparisons. In this article, we will explore how to use these methods to find the maximum value from a list using a comparator. Finding Maximum ...

Read More

Split String with Dot (.) in Java

Samual Sam
Samual Sam
Updated on 26-Dec-2024 13K+ Views

In Java, strings are one of the most commonly used data types for storing text. Sometimes, you may need to split a string based on a specific delimiter, such as a dot (.). Java provides powerful string manipulation methods like split(). Split() method  The split() method of Java String is used to divide a string into an array of substrings. This method takes a string in the form of a regular expression as a parameter, searches the currently existing string with the given pattern, and splits it at every occurrence of the pattern matched. Split String with Dot (.) in ...

Read More

Java Program to create a vertical ProgressBar

Alshifa Hasnain
Alshifa Hasnain
Updated on 24-Dec-2024 686 Views

In this article, we will learn about creating a vertical progress bar using JProgressBar.VERTICAL in Java. Progress bars are essential for tracking task completion in GUI applications, and a vertical orientation can add a unique touch to your design. What is a Progress Bar in Java Swing? A progress bar is a visual component in Java Swing that indicates the progress of a task. It can be horizontal or vertical, depending on the application's design requirements. Java Swing provides the JProgressBar class to create and manage progress bars efficiently. Features of a Vertical Progress Bar The following are features of ...

Read More

How to add a new row to JTable with insertRow() in Java Swing

Alshifa Hasnain
Alshifa Hasnain
Updated on 24-Dec-2024 8K+ Views

The JTable component in Java Swing is widely used for displaying and managing tabular data. Adding a new row dynamically to a JTable can enhance user interactivity, especially in applications that require real-time data manipulation. In this article we will tell you a step-by-step procedure, to use the insertRow() method to add a new row to a JTable, complete with a sample implementation and an algorithm. What is JTable in Java Swing? JTable is a Swing component used for displaying and editing tabular data. It is highly customizable and supports features like sorting, selection, and dynamic data manipulation, making it ...

Read More

Left justify output in Java

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 24-Dec-2024 4K+ Views

In Java, the left-justifying output means aligning text or data to the left within a specified width, with extra spaces on the right to fill the remaining space. It is commonly used when displaying tabular data or formatting strings. Left justification can be obtained using methods such as String.format() or printf(), which allow you to specify the width of the output field and the alignment of the content. Including a minus sign after the %, makes it left justified. Note − By default, output is right justified To display the Left justify output in Java is quite easy. Let us learn the following methods: ...

Read More

Printing Multi-Dimensional arrays in Java

Ankith Reddy
Ankith Reddy
Updated on 23-Dec-2024 432 Views

A multi-dimensional array can be easily printed using java.util.Arrays.deepToString() in Java. This method converts the multi-dimensional array to string and prints the array contents enclosed in square brackets. What Are Multi-Dimensional Arrays? Multi-dimensional arrays allow you to store data in a matrix-like structure, providing a way to represent tables, grids, or more complex hierarchical data. The most common type is a two-dimensional array, but Java supports arrays with more than two dimensions. int[][] array = new int[rows][columns]; Using Naive Approach The Arrays.deepToString(arr) method from the Arrays class ...

Read More

Java Program to insert styled text in a JTextPane Component

Smita Kapse
Smita Kapse
Updated on 23-Dec-2024 1K+ Views

In this article we will learn to insert styled text into a JTextPane component in Java. The JTextPane component is a versatile text editor that supports rich text features, including the ability to style text with different fonts, colors, and sizes. By leveraging the StyledDocument and Style classes, you can insert styled text dynamically into a JTextPane using Java Swing. Insert styled text in a JTextPane component using the SimpleAttributeSet and StyleConstants classes. With that, we will also use StyledDocument. Java Swing The Swing API is a collection of flexible GUI components designed to simplify the development of Java-based front-end ...

Read More

Java Program to find Product of unique prime factors of a number

Alshifa Hasnain
Alshifa Hasnain
Updated on 23-Dec-2024 766 Views

In this article, we will learn to calculate the product of the unique prime factors of a given number using Java. Prime factorization plays a crucial role in many mathematical and computational problems, and understanding how to work with prime factors can help you solve complex challenges efficiently.  Problem Statement Given a positive integer n, the task is to find the product of the unique prime factors of n. The objective is to calculate the product of all distinct prime factors of n that divide it exactly. Input  68 Output  34 Since the unique prime factors of 68 are 2 ...

Read More

Java Program for GCD of more than two (or array) numbers

Alshifa Hasnain
Alshifa Hasnain
Updated on 23-Dec-2024 737 Views

In this article, we will learn to calculate the GCD of more than two numbers in Java. We will discuss two approaches, the recursive method and an optimized approach using the Euclidean algorithm. The Greatest Common Divisor (GCD) of two or more integers is the largest integer that divides all the numbers without leaving a remainder. When it comes to an array of numbers, finding the GCD means determining the GCD of all the elements in the array. Problem Statement Given an array of integers, find the GCD of all the elements.Example −Input {7, 49, 177, 105, 119, 42} Output ...

Read More

Java Program to convert from a java.util.Date Object to a java.sql.Date Object

karthikeya Boyini
karthikeya Boyini
Updated on 23-Dec-2024 789 Views

In this article, we will learn to convert a java.util.Date object to a java.sql.Date object in Java. This is a common requirement when working with databases, as many database systems use the java.sql.Date class to represent date values. While java.util.Date is used for general date and time representation in Java, java.sql.Date is specifically designed to handle SQL-compatible date formats. java.util.Date  The Date class in the java.util package representing a specific moment in time, measured in milliseconds since January 1, 1970, UTC (the "epoch"). It's a general-purpose date and time representation. java.sql.Date A subclass of ...

Read More
Showing 1741–1750 of 4,498 articles
« Prev 1 173 174 175 176 177 450 Next »
Advertisements