String (2 1 11)
String (2 1 11)
// You can create string Object with it's value-Direct way to create
// string.
// Here STRING is called String literal(ie,. A sequence of chars
// enclosed with double quotes).
String string = "STRING CREATE";
String string2 = "*************";
// You can create string object with new keyword and constructor.
String string3 = new String("Hello M2iss");
String string4 = new String(
"String is a sequence of chars.I can't be changed once
created-immutable");
System.out.println(string);
System.out.println(string2);
System.out.println(string3);
System.out.println(string4);
}
OUTPUT
STRING CREATE
*************
Hello M2iss
String is a sequence of chars.I can't be changed once created-immutable
package com;
char[] c= {'m','2','i','s','s'};
String string = new String(c);
System.out.println("StringCreateArray");
System.out.println("*****************");
System.out.println(string);
}
}
OUTPUT
StringCreateArray
*****************
m2iss
package com;
System.out.println("Stringlength()");
System.out.println("**************");
OUTPUT
Stringlength()
**************
The length of first String is
11
The length of second String is
13
The length of Third String is
19
package com;
System.out.println("StringConcatenation");
System.out.println("*******************");
System.out.println(string);
System.out.println(string1);
System.out.println(string+string2);
}
}
OUTPUT
StringConcatenation
*******************
JavaString
Concatenation
JavaStringConcatenation
package com;
System.out.println("STRING CASES");
System.out.println("*************");
STRING CASES
*************
Given String to Lowercase:
software solution
Given String to Uppercase:
SOFTWARE SOLUTION
package com;
System.out.println("StringReplace");
System.out.println("*************");
System.out.println(string.replace('G', 'K'));
System.out.println(string2.replaceFirst("RU", "NA"));
System.out.println(string3.replaceAll("Li", "O"));
System.out.println(string2.replace("GURU BUY BRU", "RAM IS living in
Singapore"));
StringReplace
*************
KURU
GUNA BUY BRU
Ove Ofe Well
RAM IS living in Singapore
package com;
package com;
/*
* Java String class defines following methods to split Java String
* object. String[] split( String regularExpression ) Splits the string
* according to given regular expression. String[] split( String
* reularExpression, int limit ) Splits the string according to given
* regular expression. The number of resultant substrings by splitting
* the string is controlled by limit argument.
*/
// String to split.
String[] temp;
// delimiter
// print substrings
System.out.println(temp[i]);
System.out.println("");
System.out.println(temp[i]);
}
one
two
three
four
five
one
two
three-four-five
package com;
System.out.println("SubString");
System.out.println("**********");
System.out.println(string.substring(6));
System.out.println(string.substring(0,5));
}
}
SubString
**********
M2iss
Hello
package com;
System.out.println("StringEqual");
System.out.println("************");
if (string == string2) {
System.out.println("The strings are equal" + string2);
} else
System.out.println("The strings are not equal");
if (string2.equals(string3)) {
System.out.println("The strings are equal" + "" + string2);
} else
System.out.println("The strings are not equal");
if (string.equals(string3)) {
System.out.println("The strings are equal" + string);
} else
System.out.println("The strings are not equal");
}
}
StringEqual
************
The strings are not equal
The strings are equalM2iss
The strings are not equal
package com;
System.out.println("StringTrim()");
System.out.println("*************");
System.out.println("Before Trim()");
System.out.println(string);
System.out.println("After Trim()");
System.out.println(string.trim());
}
}
StringTrim()
*************
Before Trim()
RAJARAM
After Trim()
RAJARAM
package com;
System.out.println("StringSubSequence");
System.out.println("******************");
}
}
StringSubSequence
******************
World
package com;
System.out.println("StringIndexOf(char)");
System.out.println(string.indexOf('o'));
System.out.println("StringLastIndexOf(char)");
System.out.println(string.lastIndexOf('o'));
System.out.println("StringIndexOf(String)");
System.out.println(string.indexOf("Software"));
System.out.println("StringLastIndexOf(String)");
System.out.println(string.lastIndexOf("Solution"));
System.out.println("StringIndexOf(Char,FromIndex)");
System.out.println(string.indexOf('o', 6));
System.out.println("StringLastIndexOf(Char,FromIndex)");
System.out.println(string.lastIndexOf('o',6 ));
}
StringIndexOf(char)
5
StringLastIndexOf(char)
19
StringIndexOf(String)
4
StringLastIndexOf(String)
13
StringIndexOf(Char,FromIndex)
14
StringLastIndexOf(Char,FromIndex)
5
http://www.codingdiary.com/developers/developers/diary/javaapi/java/lang/SampleCode/IndexOf
StringExampleCode.html
http://download.oracle.com/javase/tutorial/java/data/manipstrings.html
http://www.tutorialspoint.com/java/java_date_time.htm