Concatenating Strings: To concatenate strings we use '+' operator
public class exercise{
public static void main(String[] args)
{
String FirstString = "Abc"
String SecondString = "def"
String FinalString;
FinalString = FirstString + SecondString;
System.out.println("Cancatenated String "+ MyString);
}
}
Length of the String: Returns the number of characters in the String.
String myStr = "abc"
System.out.println("Length of the string "+myStr.length());
IndexOf: Returns the position of the character in the String
String myStr = "abcdefg"
System.out.println("Position of the character "+myStr.IndexOf("c"));//Returns 2
System.out.println("Position of the character "+myStr.IndexOf("z"));//Returns -1 as character is not present in string
No comments:
Post a Comment