Professional Documents
Culture Documents
public class First { public static void main(String args[]) { String str = "Hello World"; char[] ch; ch = str.toCharArray(); for(int index=0; index < ch.length; index++) System.out.print(ch[index]); } }
=====================================
public class First { public static void main(String args[]) { String str="Replace Region"; System.out.println( str.replace( 'R','A' ) ); System.out.println( str.replaceFirst("Re", "Ra") );//Replaces only first occourances of given String with new one System.out.println( str.replaceAll("Re", "Ra") ); } } ==============================
} System.out.println(""); str = "one.two.three"; delimiter = "\\."; temp = str.split(delimiter); for(int i =0; i < temp.length ; i++) System.out.println(temp[i]); System.out.println(""); temp = str.split(delimiter,2); for(int i =0; i < temp.length ; i++) System.out.println(temp[i]); } } ====================================
3) static String valueOf(long l) Converts argument long to String and returns new String object representing argument long. 4) static String valueOf(double i) Converts argument double to String and returns new String object representing argument double. 5) static String valueOf(char c) Converts argument char to String and returns new String object representing argument char. 6) static String valueOf(boolean b) Converts argument boolean to String and returns new String object representing argument boolean. 7) static String valueOf(Object o) Converts argument Object to String and returns new String object representing argument Object. ====================================
public static void main(String args[]) { int i=10; float f = 10.0f; long l = 10; double d=10.0d; char c='a'; boolean b = true; Object o = new String("Hello World"); System.out.println( String.valueOf(i) ); System.out.println( String.valueOf(f) ); System.out.println( String.valueOf(l) ); System.out.println( String.valueOf(d) ); System.out.println( String.valueOf(c) ); System.out.println( String.valueOf(b) ); System.out.println( String.valueOf(o) ); }