Arithmetic Operations Between BigDecimal and Primitive Data Types in Java

Mr. Satyabrata
Updated on 23-Jan-2025 23:07:25

397 Views

In this article, we will explore how to perform arithmetic operations between BigDecimal and Primitive data types by using Java. For instance, Addition: The sum of a BigDecimal object with a value of 10.50 and an int primitive with a value of 5 is a BigDecimal object with a value of 15.50. 10.50 + 5 = 15.50 SyntaxThe syntax doubleValue() method returns the value of a BigDecimal object as a double primitive type. double doubleNum1 = num1.doubleValue(); Where “num1” is a BigDecimal object. What is BigDecimal in Java? BigDecimal is a class in Java's java.math package that ... Read More

Count Inversions of Size Three in a Given Array

Rudradev Das
Updated on 23-Jan-2025 23:06:37

348 Views

In this article, we will learn how to count inversions of size three in a given array. The goal is to find how many triplets (i, j, k) exist such that i < j < k and arr[i] > arr[j] > arr[k].Understanding Inversion Count Inversion count is a step-counting method by which we can calculate the number of sorting steps taken by a particular array. It is also capable of counting the operation time for an array. But, if we want to sort an array in a reverse manner, the count will be the maximum number present in that array. Array: ... Read More

Implement Binary Search on Float Array in Java

Ankith Reddy
Updated on 23-Jan-2025 23:06:21

351 Views

In this article, we will learn how to implement binary search on a float array in Java using the Arrays.binarySearch() method. Binary search on a float array can be implemented by using the method java.util.Arrays.binarySearch(). This method returns the index of the required float element if it is available in the array, otherwise, it returns (-(insertion point) - 1) where the insertion point is the position at which the element would be inserted into the array. Java.util.Arrays.binarySearch(). methodThe Arrays.binarySearch() method in Java searches for a specified element in a sorted array. It returns the index of the element ... Read More

Convert ArrayList to String and Vice Versa in Java

AmitDiwan
Updated on 23-Jan-2025 23:00:23

479 Views

In this article, we will understand how to convert the ArrayList into a string and vice versa. The ArrayList class is a resizable array, which can be found in the java. util package. The difference between a built-in array and an ArrayList in Java is that the size of an array cannot be modified. ArrayList definitionAn ArrayList in Java is a resizable array found in the java.util package, which allows for dynamic modifications in size as elements are added or removed. It supports ... Read More

Get JDBC Major Version Using DatabaseMetaData in Java

Vikyath Ram
Updated on 23-Jan-2025 22:54:33

327 Views

In this article, we will learn how to retrieve the major version of the JDBC driver using the getJDBCMajorVersion() method of the DatabaseMetaData interface in Java. This method is useful for checking the version of the JDBC driver in use. getJDBCMajorVersion() method The getJDBCMajorVersion() method of the DatabaseMetaData interface returns the major version of the JDBC driver in integer format. To get a major version of the JDBC driver − Make sure your database is up and running. ... Read More

Convert String to Float in Java

karthikeya Boyini
Updated on 23-Jan-2025 22:54:22

266 Views

In this article, we will learn how to convert a string to a float-type number in Java. We will use the Float.parseFloat() method to perform this conversion. Float.parseFloat() method The Float.parseFloat() method belongs to the Float class in Java and is used to convert a string representation of a number into a primitive float. If the string does not contain a valid float representation, it throws a NumberFormatException. NumberFormatException: Thrown to show that the application has attempted to convert a string to one of the numeric types, but that the string does not have the appropriate format. ... Read More

Java Program to Compare Strings

Samual Sam
Updated on 23-Jan-2025 22:54:05

6K+ Views

In this article, we will compare two Strings in Java using the compareTo() method, equals() method, or == operator. Each approach serves a specific purpose in comparing strings, whether it's lexicographical comparison, checking for content equality, or comparing object references. Using the compareTo() methodThe compareTo() method compares two strings. The comparison is based on the Unicode value of each character in the strings. The character sequence represented by this String object is compared lexicographically to the character sequence represented by the argument string. The result is a negative integer ... Read More

Replace All Occurrences of Given String in Java

Samual Sam
Updated on 23-Jan-2025 22:53:32

366 Views

In this article, we will learn how to replace all occurrences of a given string with a new one using the replaceAll() method in Java. This method is particularly useful when we want to modify specific parts of a string.   replaceAll() method The replaceAll() method in Java is used to find substrings within a string that match a specified regular expression and replace them with a given string. This method performs a search for all occurrences that match the provided regex pattern and replaces them with the new string.Syntax public String replaceAll(String regex, String replace_str) Steps to replace all occurrences ... Read More

Get Time and Date Functions Using DatabaseMetaData in Java

Vikyath Ram
Updated on 23-Jan-2025 22:53:19

134 Views

In this article, we will learn how to retrieve the list of time and date functions in the database using the getTimeDateFunctions() method of the DatabaseMetaData class in Java. getTimeDateFunctions() The getTimeDateFunctions() method retrieves the list of time and date functions supported by the current database. The names returned by this method are the Open CLI time and date function names. Steps to Retrieve Time and Date Functions in Database To get the list of the time and date functions supported by the underlying database − Step 1: Register the Driver: Make sure your database is ... Read More

Java SQL Time setTime Method with Example

Vikyath Ram
Updated on 23-Jan-2025 22:31:05

695 Views

In this article, we will learn the usage of the setTime() method in Java with a complete example. Handling time-related data is an essential aspect of many Java applications, especially when interacting with databases. The java.sql.Time class, designed to handle SQL TIME values. What is setTime() method The setTime() method of the java.util.Time class accepts a variable of long type, representing the number of milliseconds from the epoch time (January 1, 1970, 00:00:00.000 GMT) to the required time, and sets the specified time value to the current Time object. //Setting time time.setTime(time_value_in_long); Use Cases of setTime() Following are the use ... Read More

Advertisements