String Array
String Array:
• A String array is a collection of string with a fixed number of
values.
• First element of string array is placed at Index 0, second at
Index 1, and so on.
• You can declare a string array without size or with size :
String[] Strname;
String[] strname=new String[2];
Both above statement are correct:
Characteristics of string array:
• It can be initialized either at time of declaration or by
populating the values after the declaration.
• The String can be iterated using the for loop.
• The searching & sorting operation can be performed on
the string array.
import [Link];
// Print the states using a simple for lo
public class IndiaStates {
[Link]("\nStates of India:"
public static void main(String[] args) {
for (int i = 0; i < numberOfStates; i++
Scanner scanner = new Scanner([Link]);
[Link](states[i]);
}
// Prompt user for the number of states
[Link]("Enter the number of states
// Close the scanner
in India: ");
[Link]();
int numberOfStates = [Link]();
}
[Link](); // Consume the newline
}
character
// Declare the array to hold state names
String[] states = new
String[numberOfStates];
// Input state names using a simple for loop
for (int i = 0; i < numberOfStates; i++) {
[Link]("Enter the name of state
" + (i + 1) + ": ");
states[i] = [Link]();
}
Character Data in Java
• It is enclosed in single quotes.
• It is Primitive data type.
• It occupies 2 bytes of memory space.
• Eg: char ch=‘a’;
Character Methods
• [Link](ch);
• [Link](ch);
• [Link](ch);
• [Link](ch);
• [Link](ch);
• [Link](ch);
• [Link](ch);
• [Link](ch);