By: aathishankaran in Java Tutorials on 2007年02月01日 [フレーム]
Character Arrays
Arrays are not confined to numeric elements only. They also can consist of characters. A string is stored as an array of characters.
To assign values to character array, the following is written:
Char_array[0] = 'B';
Char_array[1] = 'I';
Char_array[2] = 'N';
Char_array[3] = 'G';
Char_array[4] = 'O';
It can also be done as:
Char_array = "BINGO";
Since a string can be of any length, the end of the string is marked with the character '0円', known as a string terminator
B I N G O 0円 Subscripts-> 0 1 2 3 4 5
A string terminator is automatically appended when a character array is initialized with asset of characters (Char_array = "BINGO"} and whenever a string is accepted using the keyword accept.
While declaring a character array, the array must be large enough to hold the longest string that is to be read, plus one extra element to hold the string terminator.
Initializing Character Arrays
char City[11] = "CALIFORNIA";
Example : Finding the length of a character array.
PROGRAM_LEN
{
char String[81]
integer Length;
display "Please Enter a String:";
accept String;
Length = 0;
While ( String [Length] !='0円')
{
Length=Length+1;
}
display "Length of the String is";
display Length
}
Scanning character by character in an array is also termed as traversing.
This policy contains information about your privacy. By posting, you are declaring that you understand this policy:
This policy is subject to change at any time and without notice.
These terms and conditions contain rules about posting comments. By submitting a comment, you are declaring that you agree with these rules:
Failure to comply with these rules may result in being banned from submitting further comments.
These terms and conditions are subject to change at any time and without notice.
Most Viewed Articles (in Java )
Step by Step guide to setup freetts for Java
Open a .docx file and show content in a TextArea using Java
concurrent.Flow instead of Observable class in Java
DateFormat sample program in Java
Simple Port Scanner application using Java
Using the AWS SDK for Java in Eclipse
Read a file having a list of telnet commands and execute them one by one using Java
Calculator application in Java
Latest Articles (in Java)
Read a file having a list of telnet commands and execute them one by one using Java
Open a .docx file and show content in a TextArea using Java
Step by Step guide to setup freetts for Java
Of Object, equals (), == and hashCode ()
Using the AWS SDK for Java in Eclipse
DateFormat sample program in Java
concurrent.Flow instead of Observable class in Java
Calculator application in Java
Sending Email from Java application (using gmail)
Read a file having a list of telnet commands and execute them one by one using Java
Open a .docx file and show content in a TextArea using Java
Step by Step guide to setup freetts for Java
Of Object, equals (), == and hashCode ()
Using the AWS SDK for Java in Eclipse
DateFormat sample program in Java
concurrent.Flow instead of Observable class in Java
Calculator application in Java
Sending Email from Java application (using gmail)
© 2023 Java-samples.com
Tutorial Archive: Data Science React Native Android AJAX ASP.net C C++ C# Cocoa Cloud Computing EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Trends WebServices XML Office 365 Hibernate
Latest Tutorials on: Data Science React Native Android AJAX ASP.net C Cocoa C++ C# EJB Errors Java Certification Interview iPhone Javascript JSF JSP Java Beans J2ME JDBC Linux Mac OS X MySQL Perl PHP Python Ruby SAP VB.net EJB Struts Cloud Computing WebServices XML Office 365 Hibernate