We will show in this post on how to convert an ArrayList to a Array in Java. Although ArrayList are usually more flexible and powerful, sometimes we need to convert it to simple arrays. Most common use case is passing as parameter to a third party API, that we have no liberty of modifying. Check the samples below.
It is a common scenario in programming when we wish to check if one String contains a specific substring. For example, we wish to test if the String "The quick brown fox" contains the substring "brown". The Java String class has a method contains() that can help with this case. Below are examples on how to use Java String's contains method.
When dealing with numbers that are not whole, the type double is usually used for convenience because it is primitive and has good precision. However, when a double variable is converted to String, most of the time the result is in exponential or scientific notation. Below are some examples on how to perform in Java the conversion from double to String without exponential or scientific notation.
In most cases where precision is important, we work with numbers having decimal point rather than whole numbers. For example, computation of points in 3D space - float will be more ideal for this. But later on, we need to convert back the float value to an integer when we want to know which coordinate on the screen it represents. This is just one scenario for the need of converting a Java float to int. There could be many more use cases. In case you also need it in your program, below are some examples on how to convert a float 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 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.
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.
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.
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 ...