Thursday, 23 May 2013

SOME COMMON STRING FUNCTIONS IN JAVA


Here are some of the predefined String function in Java. These functions are very fundamental and are frequently used in string manipulations.
I have included three basic string functions in this post, these are mentioned below:-

  1. To find the length of string.
  2. To find the nth character of the string.
  3. To concatenate two strings.
SOURCE CODE :--

/********************************************************************************/
public class stringtest {

public static void main(String[] args) {
String str1="Hello World";
String str2="Hello Lavish";

System.out.println(str1.length()); //finding length of str1

System.out.println(str1.charAt(6)); //finding (6+1)th character in str1
//here the argument of charAt() function is the index number that starts from zero

System.out.println(str1.equals(str2)); //checking whether str1 is equal to str2 or not

String str3=str1+str2; //concatinating two different strings
System.out.println(str3); //printing concatenated strings
}

}
/********************************************************************************/

No comments:

Post a Comment