Grails Cookbook - A collection of tutorials and examples

Sort String Array in Java

String Array is a very useful data structure when we need to hold multiple String values. It is very simple to understand for programmers with background in some other language. It is also easy to use for many programming scenarios. But one common thing we usually need when working with Arrays, is that we sometimes need the data to be ordered or sorted. Below are some examples on how to Sort String Array in Java.

Check If String Array Contains a Value In Java

Arrays are very useful when we need to work with multiple values of the same type. For example, we may need multiple instances of Strings. Arrays provide a data structure that is easy to learn and use. But since arrays are simple, it does not have much methods for some operations we may need. Below are examples on how to test or check if a String Array contains a certain value in Java.

How To Add element to String Array in Java

Working with arrays in Java is common because this data structure is simple to use and very efficient. Most programming language supports arrays, so many developers may have idea on how to use it without reading much documentation. Specially for programmers coming from C or C++ background, the way on how to use it is very similar. But there is one big limitation when working with Arrays in Java, the length or size of Arrays are fixed. Meaning we can not increase or decrease the size without programming tricks. Below are some examples on how we can add element to a String Array in Java.

Two Dimensional String Array in Java

One-dimensional arrays in Java are commonly used in everyday programming. However, there are instances where we need two-dimensional array. An example is holding data for a table listing with multiple columns and rows. Another example is holding information about a board game like chess. Below are some example on how to work with Two Dimensional String Array in Java.

Iterate Through String Array in Java

A String Array is a data structure that holds several String values. The number of String elements is fixed and can't be changed throughout the lifetime of the array object. One common thing that we wish to do with String Array is to go through all the data it contains and process individually. Below contains examples on how to iterate through String Array in Java.

String Array Length in Java

String Array is a commonly used data structure when programming in Java. Although we can generally use List for greater flexibility, but sometimes using String Array is more suitable for a given scenario. Arrays in general have the property of having fixed number of elements and the size can't be changed throughout the lifetime of the data structure. When given a String Array as parameter to our method, it is common that we wish to know the length of it. Below are some examples on how to get the length of a String Array in Java.

Byte Array to String in Java

There are programming scenarios where we have a data in byte array that represents a String. This could be a case when we use a third party library to load data somewhere and the result is a byte array. In such cases, we may want to convert back the byte array to a String. Below are some examples on how to convert a byte array to String in Java.

Java String Array Declaration

An array is a basic and essential data structure in Java. It holds a fix number of values that can be easily manipulated. It is common to use an array of immutable objects in Java, such as a String. But before we can use a String Array, we must first be able to declare it. Below are some examples on how to declare a String Array in Java.