import java.io.*;
import java.lang.*;
class StringFunctions {
public static void main(String[] args)throws IOException {
DataInputStream in = new DataInputStream(System.in);
System.out.println("Enter first String: ");
String str1 = in.readLine();
System.out.println("Enter second string: ");
String str2 = in.readLine();
String str3 = str1 + str2;
System.out.println("Concatenation of strings is: " + str3);
boolean l = str1.equals(str2);
System.out.println("String are equal: " + l);
l = str1.equalsIgnoreCase(str2);
System.out.println("String are equal ignoring Upper/Lower case: " + l);
char loc = str1.charAt(2);
System.out.println("Char at third location of second string is: " + loc);
System.out.println("Enter the new string of length greater then 5: ");
String nstr;
nstr = in.readLine();
if ((nstr.length())>=5) {
String s = nstr.substring(2,5);
System.out.println("Substring from second location to fifth location is: " + s);
s = nstr.substring(2);
System.out.println("Substring from second location: " + s);
s = nstr.replace('a','m');
System.out.println(s);
char[] buf = new char[str2.length()];
nstr.getChars(0,3,buf,0);
System.out.println(buf);
byte[] buf1 = new byte[str2.length()];
nstr.getBytes(0,3,buf1,0);
System.out.println(buf1);
}
else {
System.out.println("Length of string is less than 5");
}
}
}
Output
Enter first String:
Rahul
Enter second string:
Salunkhe
Concatenation of strings is: RahulSalunkhe
String are equal: false
String are equal ignoring Upper/Lower case: false
Char at third location of second string is: h
Enter the new string of length greater then 5:
Salunkhe
Substring from second location to fifth location is: lun
Substring from second location: lunkhe
Smlunkhe
Sal
[B@1be6f5c3
0 Comments