Java Articles

Page 177 of 450

Java 8: Difference between two LocalDateTime in multiple units

Aniket Jain
Aniket Jain
Updated on 17-Dec-2024 465 Views

Difference Between Two LocalDateTime Java 8 introduced a powerful Date and Time API that provides developers with better control over date and time operations. One common requirement is to calculate the difference between two LocalDateTime objects in various units such as days, hours, minutes, and seconds. This article explains how to achieve this using Java 8's Duration and ChronoUnit classes. Understanding LocalDateTime LocalDateTime is a class in Java 8 that represents a date-time without a time-zone. It is often used in applications where the time zone is not needed. Calculating differences between two LocalDateTime instances is straightforward with the new ...

Read More

Java program to find all close matches of input string from a list

Alshifa Hasnain
Alshifa Hasnain
Updated on 17-Dec-2024 816 Views

Finding close matches to a string from a list of words is a common problem in string manipulation and pattern recognition. This article demonstrates two effective approaches for solving this problem in Java. The first approach utilizes string encoding to identify similar patterns, while the second approach leverages the Levenshtein Distance algorithm to find approximate matches. String Encoding Approach The string encoding approach is a clever technique where each string is transformed into a unique encoded format. Strings with the same encoded pattern are considered matches HashMap A HashMap in Java is a collection that stores key-value pairs, where keys ...

Read More

Java program to print ASCII value of a particular character

Lakshmi Srinivas
Lakshmi Srinivas
Updated on 17-Dec-2024 1K+ Views

In this article, we will learn to print the ASCII value of a particular character in Java. ASCII (American Standard Code for Information Interchange) is a standard encoding system that assigns a unique numeric value to characters like letters, digits, and symbols. We’ll explain the concept of ASCII, demonstrate how to retrieve and display ASCII values in Java and provide practical examples to help you understand and apply this concept effectively. What Is ASCII? ASCII is a character encoding standard where each character (letters, digits, and symbols) is assigned a numeric value. For instance − ...

Read More

Java program to check whether a given string is Heterogram or not

Alshifa Hasnain
Alshifa Hasnain
Updated on 17-Dec-2024 666 Views

A heterogram is a string where each letter appears only once, with no repeated characters. This property makes it unique and an interesting problem to solve in Java. In this article, we will learn to determine whether a given string is a heterogram using a frequency-based approach and introduce an alternative using a Set. Set A Set is a type of Collection designed to hold unique elements, ensuring no duplicates are present. It reflects the concept of a mathematical set and includes methods from the Collection interface while enforcing this rule of uniqueness. Using an Array for Character Frequency  This ...

Read More

Convert Integer to Hex String in Java

Revathi Satya Kondra
Revathi Satya Kondra
Updated on 14-Dec-2024 15K+ Views

In Java, converting an integer value to a hexadecimal (hex) string means transforming the number from its base-10 (decimal) format to base-16 format. This conversion uses digits 0-9 and letters A to F to represent the values. Integer: An integer is a whole number without having a fractional part, such as -2, -1, 0, 1, 2, etc. Hex String: A hexadecimal (hex) string represents a number in base-16, using digits 0-9 and letters A-F. We represent the A-F in numbers as 10 to 15. Example Let’s say the following are our integer values. int val1 = 5; int val2 ...

Read More

Java Program To Reverse A Number And Check If It Is A Palindrome Number

Rudradev Das
Rudradev Das
Updated on 13-Dec-2024 4K+ Views

What is a Palindrome Number? If a number is given (two, three or four-digit number) and reversing each individual number with the positions from front to back and then vice versa , and then if the number output is the same after reversing all the elements then it is said to be a palindrome number. Just like we will check whether the string or array is palindrome number. String - A string is a storing capsule or a storing method in which we can store a sequence of characters in a Java program. Array - An array is a collection ...

Read More

Java Program for Pigeonhole Sort

Alshifa Hasnain
Alshifa Hasnain
Updated on 13-Dec-2024 561 Views

In this article, we will learn Pigeonhole Sort in Java, a sorting algorithm designed for arrays with a small range of integer values. It organizes elements into "pigeonholes" based on their values and then reconstructs the sorted array. We’ll discuss two approaches: a basic method using arrays and an optimized approach using LinkedLists. What is Pigeonhole Sort? Pigeonhole Sort works by distributing elements into a range of buckets based on their values. It is most effective when the range of input values is relatively small compared to the size of the dataset. The algorithm ensures stability and simplicity in sorting ...

Read More

Java Program to Save Decimal

Alshifa Hasnain
Alshifa Hasnain
Updated on 13-Dec-2024 988 Views

In this article, we will learn two ways to handle decimal values in Java. First, we will use the BigDecimal class to ensure precision when working with decimals. Then, we will use the DecimalFormat class to format decimal values. Both examples will show how to scale decimal values to three places. Different Approaches to Save Decimal Values The following are the two approaches to save decimal values in Java − Using BigDecimal Using DecimalFormat Save Decimal Values Using BigDecimal for Precision Control The BigDecimal class of java.math package is used for ...

Read More

Java Program to get frequency of words with Lambda Expression

Alshifa Hasnain
Alshifa Hasnain
Updated on 13-Dec-2024 755 Views

In this article, we will learn how to calculate the frequency of words in a text using Java and Lambda Expressions. By leveraging concise syntax and functional programming techniques, we can efficiently process text data and determine word occurrences. This approach is particularly useful for applications like text analysis and natural language processing. What is Lambda Expression? A lambda expression in Java is a concise way to represent an anonymous function(a function without a name). Introduced in Java 8, it simplifies the implementation of functional interfaces (interfaces with a single abstract method), enabling cleaner and more readable code. Syntax of ...

Read More

Java Program for Pancake sorting

Alshifa Hasnain
Alshifa Hasnain
Updated on 13-Dec-2024 791 Views

In this article, we will learn pancake sorting which is a unique way to sort an array by flipping sections of it. The algorithm finds the largest unsorted element, flipping it to the front, and then flipping it to its correct position. Although not the fastest sorting method, it’s an interesting and creative way to learn about problem-solving and data manipulation. This article explains the algorithm in simple steps and shows how to implement it in Java. What is Pancake Sorting? Pancake sorting is a sorting technique that resembles selection sort, i.e. sorting the largest element first thereby reducing the ...

Read More
Showing 1761–1770 of 4,498 articles
« Prev 1 175 176 177 178 179 450 Next »
Advertisements