VOOZH about

URL: https://www.geeksforgeeks.org/java/string-arrays-in-java/

⇱ String Arrays in Java - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

String Arrays in Java

Last Updated : 2 Oct, 2025

A String Array in Java is an array that stores string values. In this article, we will learn the concepts of String Arrays in Java including declaration, initialization, iteration, searching, sorting, and converting a String Array to a single string.

Iterating Over String Arrays

To iterate through a String array we can use a looping statement. So generally we have three ways to iterate over a string array.  


Output
Apple Banana Orange 
Apple Banana Orange 
Apple Banana Orange 


Searching in a String Array

To find an element from the String Array we can use a simple linear search algorithm.


Output
Available at index 1


Sorting a String Array

Sorting a String array means to sort the elements in lexicographical (dictionary) order. We can use the built-in sort() method to do so and we can also write our own sorting algorithm from scratch.


Output
Apple Avocado Ball Banana Cartoon Cat 


Converting String Array to String

Using Arrays.toString()

To convert from String array to String, we can use a Arrays.toString() method or a custom approach.


Output
[She, is, a, good, girl]

Explanation: Here, the String array is converted into a string, but one thing to note here is that comma(,) and brackets are also present in the string.

Custom Conversion Without Brackets and Commas

To create a string from a string array without comma(,) and brackets , we can use the below code snippet.


Output
She is a good girl

Declaration of String Arrays

A String array can be declared with or without specifying its size. Below is the example:  

String[] str0; // declaration without size String[] str1 = new String[4]; //declaration with size

In the above example,

  • str0 is declared without specifying its size.
  • str1 is declared with a size of 4.

We can use both of these ways to declare String array in Java.

Initialization of String Arrays

Declaring and Initializing Together

In this method, we are declaring the values at the same line.

String[] arr0 = new String[]{"Apple", "Banana", "Orange"};

Using Short Form

This method is the short form of the first method i.e. initialize the array at the time of declaration.

String[] arr1={"Apple","Banana","Orange"};

Declaring First, Initializing Later

In this method, we are declaring the String array with size first and after that we are storing data into it.

String[] arr2=new String[3];
arr2[0]="Apple";
arr2[1]="Banana";
arr2[2]="Orange";

Comment
Article Tags: