Skip to main content
Advertisement

5.2 String Arrays

An array where the type is String refers to an array capable of holding multiple strings. Java’s String is a special class that is the most frequently used of all data types.

1. Declaration and Creation of String Arrays

You can handle it identically to primitive arrays like int, but intrinsically, it differs in that the data stored inside is objects (specifically, string literals).

String[] name = new String[3]; // Allocated an empty string array with size 3

Each space in a primitive array must directly contain data directly, but inversely, the default primitive initial value has physical parameters. Because String arrays consist of reference variables, assigning it a class with no intended initial reference automatically resolves to null.

Initialization of String Arrays

The method for providing arrays with explicit underlying string values explicitly.

String[] season = {"Spring", "Summer", "Autumn", "Winter"};

String[] name = new String[3];
name[0] = "Kim";
name[1] = "Lee";
name[2] = "Park";

2. Characteristics of String Objects

This isn’t only a trait of the array alone; these are central aspects governing the widespread String class (which inherently has deep relationships with arrays).

  1. Strings carry immutability. Thus, the internal text does not mutate; assignment merely rewrites with entirely new references.
  2. In reality, each string sequence inside utilizes an intrinsic char[] configuration.

Given strings are effectively sequences of characters (char arrays), they intrinsically contain functional mechanisms associated with arrays permitting specific information extraction inside like index isolation and parameter checking.

Principal Methods tied implicitly to String Arrays

These features often aid in retrieving isolated data parts dynamically handled effectively from specific String texts:

  • charAt(int index): Returns the specific character residing logically at its positional index metric.
  • length(): Explicitly evaluates string text's character sequence length (Contrasting an array's length attribute, strings treat it structurally via method function via ()).
  • substring(int from, int to): Gathers specific sections comprising localized string text sequences (substrings).
  • equals(Object obj): Methodically compares sequences regarding text-content logic identicalness objectively.

3. Command Line Arguments Parameters

Often referenced primarily right beside our execution's gateway is indeed the main method notation globally observed: public static void main(String[] args) { }

This parameter defined implicitly as String[] args exactly utilizes this String array schema. When running a Java implementation inside a command terminal separated sequentially via spaces, standard parameters populate array attributes flawlessly triggering processing accordingly.

From command console execution parameters: java MainTest abc 123 "Hello Java" Upon execution similar logically up above, specifically three unique segments systematically funnel perfectly straight down inside its array functionally.

Advertisement