Array is the most basic way to represent a group of data with unknown size. Collections has been popular in recent years but arrays will always have a good use case because of it's simplicity. But before we could use an array, we should now how to create an instance. Below are some examples on how we can create array in Java.
Programmers usually want to use arrays because it can hold arbitrary number of items, depending on how we created the array object. Most of the things we wish to do with arrays, like searching or sorting, needs us to know it's size. Because we usually manipulate arrays using loop, we need to know the size of an array to know how many times we need to loop. We will show how to find Java Array Size and give some examples on how to use it.
We usually use integers when we want to calculate whole numbers. But Integers in Java can only hold 32 bit values which could be insufficient for some tasks. When we need bigger range of values, we could use long values. In Java, Long values is represented in 64 bits. However, even if this can hold bigger range of values, there is still a limit to it's maximum value. The Java Long Max Value is 9,223,372,036,854,775,807. Below are some more details to explain this.
Int or Integer is one of the common data type that we will encounter in Java since most programming involves calculations, and integers are the most basic numbers we could manipulate. We should take note however that Integers can't have arbitrarily large value. In fact it has a maximum value. The Java Integer Max Value is 2,147,483,647. Below are some more details to explain this.
Array is one of the favorite data structure in Java and in other languages. It is so simple to use and easy to manipulate. And so we wish to do some operations to it from time to time. For now, we will discuss the problem of how to copy array in Java. There are two things to consider, do we want a partial copy or a full copy? For partial, we only want to copy spme items from an array, and in full copy, we wish to copy everything. Below are some examples of how to copy an array in Java.
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.