JAVA - TM - String Operations
JAVA - TM - String Operations
Introduction
String manipulation is the most common operation performed in Java programs. The easiest way to represent a String (a sequence of characters) is by using an array of characters.
Although character arrays have the advantage of being able to query their length, they themselves are too primitive and dont support a range of common string operations. For example, copying a string, searching for specific pattern etc. Recognising the importance and common usage of String manipulation in large software projects, Java supports String as one of the fundamental data type at the language level. Strings related book keeping operations (e.g., end of string) are handled automatically.
Following are some useful classes that Java provides for String operations.
String Class StringBuffer Class
String Class
Strings Basics
Length of string can be accessed by invoking length() method defined in String class:
Strings Arrays
String city = New + York; String city1 = Delhi; String city2 = New +city1;
String city[] = new String[5]; city[0] = new String(Melbourne); city[1] = new String(Sydney); String megacities[] = {Brisbane, Sydney, Melbourne, Adelaide, Perth};
6
String(char c[])
String(char c[], int SI, int numchars) String(byte b[])
StringDemo Output
java StringDemo
String Length = 15 Modified String = Have a Nice Day Converted to Uppercase = HAVE A NICE DAY Converted to Lowercase = have a nice day
11