Developers loves to use arrays to store multiple values whenever possible because of it's simplicity and ease of use. It is not very flexible as the other classes in the collections API, but all codes for it are very simple and easy to understand. Once we have stored multiple values, we usually want the reverse order for some other processing. For example, if an array is listed in ascending order, we may want to reverse it to get the descending order. Below are some examples of how we could reverse an array in Java.
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.
When we are dealing with small number of data, we can use a variable for each data we need to monitor. If we don't know how much data we need to process, or if the data is large, an array is very useful. A Java Integer Array is a an array object that holds multiple Integer values, if we need many int values in our computation. Below are some examples on how to use int array in Java.
Arrays are usually useful when working with arbitrarily large number of data having the same type. It is usually convenient if we can print the contents of an array. Below are some examples on how to print the contents of an Array in Java.