JavaDevNotes.com

Java Double To Int

It is convenient to use doubles on calculations because of the flexibility on precision. But once we are done with complex computation, we would wish to extract the integral part of the result. This post will show how to convert a Java double to int. Several examples will be given for extracting the result of double to int.

Prime Number Program in Java

Prime Number is a concept in math, specifically in number theory. A Prime Number is a whole number greater than 1 that has no positive divisors except 1 and itself. For example, the number 7 is prime because it has no other divisor except 1 and 7. While 6 is not a prime number because 2 and 3 can divide it. If you need to write a program that needs to check if a number if prime or not, below are some examples for Prime Number Program in Java.

Java Sort Array Examples

An array is a common data structure in many languages. It is simple and easy to understand, hence it is commonly used in many situations. However, it is very common requirement to sort a an array or a collection of objects to ensure elements are in specific order (E.g. increasing order of value). If you need to learn how to perform this operation, below are some examples on how to Sort an Array in Java.

Java List to Array Examples

Although a List is a more powerful than an array, there are cases where we wish to convert the former to the latter's data structure. For example, if there is an existing API where the expected parameter is an Array, but what you have is a List. If you find yourself on such situations, here are some ways that can help you on how to convert a Java list to array.

Java Array to List Examples

Sometimes it is needed to convert a Java array to List or Collection because the latter is a more powerful data structure - A java.util.List have many functionality that ordinary array do not support. For example, we can easily check if a List ...

Java Array To String

Java objects have the toString() method to convert the instance to it's String representation. If you will try to invoke the toString() method of an Array, the result will be some weird String like [I@70f9f9d8. This does not seems logical, say for example you wish to write the String to logs. It is more useful to convert a Java Array to a String that gives human understandable results. Below are some examples on how to do that.

Java String Array Examples

A Java String Array is an object that holds a fixed number of String values. Arrays in general is a very useful and important data structure that can help solve many types of problems. It's simplicity on how to access contents through index makes it powerful yet user-friendly. Here are some examples on how to use String Array in Java.

Java String Replace Tutorial And Examples

The Java String replace method can be used to replace a character or a string sequence from an instance of a String, with a new value of character or a String sequence. This is very useful in problems that needs String manipulations. ...

Java Substring Examples

The substring method of String is very useful in Core Java Programming. It is a fundamental method in performing String manipulation. What it does is extract a sequence of characters from a String and return that as a new String object. This post will show examples on how to use the Java substring method.

Java Left Pad String Examples

Here are some example codes to pad a custom character to the left side of a String to achieve a target length.