String Final
String Final
String Final
String:
• It represents a sequence of characters enclose in a double
quotes(“ “).
• In java it is not represented using character array.they are
represented using classes string.
• A java String ia an instantiated object of a String class. It
is not a character array.
• Syntax:
• String string_name = new String(“string value”);
• E.g
• String city = new String(“Aurangabad”);
• String class method:
System.out.println(“length of string=“+size);
• Syntax : s2 = s1.toLowerCase();
• String s2 = s1.toLowerCase();
• System.out.println(s2);
• o/p : java
• toUpperCase(): it is used to convert all characters in a string to
uppercase. Non alphabetical characters such as digits & special
symbols are not affected.
• Syntax : S2 = s1.toUpperCase();
• String s2 = s1.toUpperCase();
• System.out.println(s2);
• o/p JAVA
• replace() : it replaces all of one character with another
character.
• Syntax: Stringname.replace(‘source_char’,’dest_char’);
• System.out.println(temp);
• o/p BALL
• charAt() :
• Syntax :
• V= String_name.charAt(position)
• Char ch = s1.charAt(1);
• System.out.println(ch); // output : b
• Concat() :
• String s2 = s1.concat(“Afternoon”);
• System.out.println(s2);
• We pass begin index and end index number position in the java substring method.
• Syntax :
• and
String s1="Javatpoint";
System.out.println(substr);
System.out.println(substr2);
Output:
Javatpoint
point
String s1="javatpoint";
String s2="javatpoint";