0% found this document useful (0 votes)
15 views6 pages

Declaring String Arrays in Java

The document explains the concept of String arrays in Java, including their declaration, initialization, and characteristics such as iteration and the ability to perform searching and sorting operations. It also provides a sample Java code for inputting and printing state names from an array. Additionally, it covers the character data type in Java, its properties, and various methods associated with it.

Uploaded by

priyanka.barve
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
15 views6 pages

Declaring String Arrays in Java

The document explains the concept of String arrays in Java, including their declaration, initialization, and characteristics such as iteration and the ability to perform searching and sorting operations. It also provides a sample Java code for inputting and printing state names from an array. Additionally, it covers the character data type in Java, its properties, and various methods associated with it.

Uploaded by

priyanka.barve
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd

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);

You might also like