Generic selectors
Exact matches only
Search in title
Search in content
Post Type Selectors

Java program use of String

public class StringConstructor {

            public static void main (String args[]){
                        char  arr[ ] = { ‘x’, ‘y’, ‘z’};
                        String st = new String ( arr );
                        System.out.println(st);
                        }

}

public class Arith {

            String fname =“TSPC”;
            String lname = “TSGI”;
            void show(){
                        System.out.println(“The full name is “+fname+ ” “ +lname);
            }
           
            public static void main(String[] args) {
                        // TODO Auto-generated method stub
Arith a1 = new Arith();
a1.show();
            }


}

public class buf {

            /**
             * @param args
             */
            public static void main(String[] args) {
                        // TODO Auto-generated method stub
String foo = “foo”;
String s = “abc” + foo + “def” + Integer.toString(47);
System.out.println(s);
//The equivalent using StringBuffer;
StringBuffer sb = new StringBuffer(“abc”); // Creates String;
sb.append(foo);
sb.append(“def”); //Creates a string
sb.append(Integer.toString(47));
System.out.println(sb);


            }


}

public class equaldemo {

            /**
             * @param args
             */
            public static void main(String[] args) {
                        // TODO Auto-generated method stub
String s1 = “Hello”;
String s2 = “Hello”;
String s3 = “Good bye”;
String s4 = “HELLO”;
System.out.println(s1+ “equals” +s2+ “is” +s1.equals(s2));
System.out.println(s1+ “equals” +s3+ “is” +s1.equals(s3));
System.out.println(s1+ “equals” +s4+ “is” +s1.equals(s4));

            }


}

public class hash {

            /**
             * @param args, class name cant be Hash, because ists predefined name of class
             */
            public static void main(String[] args) {
                        // TODO Auto-generated method stub
                        String s1 = “hello”;
                        String s2 = “Hello”;
                        System.out.println(“Tha hash code for”+s1+ “is” +s1.hashCode());
                        System.out.println(“The hash code for”+s2+ “is” +s2.hashCode());
                       
            }


}

public class st {

            /**
             * @param args
             */
            public static void main(String[] args) {
                        // TODO Auto-generated method stub
                        String s = “Now is the time for all good men” + “to come to the aid of their country” + “and pay their taxes”;
                        String s1 = “Hello World”;
                        String s2 = “Hello”;
                        String s3 = “HELLO”;
                        System.out.println(“Index of t = “ +s.indexOf(‘t’));
                        System.out.println(“last index of t = “ +s.lastIndexOf(‘t’));
                        System.out.println(“index of (t,10) =” +s.indexOf(‘t’,10)) ;
                        System.out.println(“last index of (t,60)=” +s.lastIndexOf(‘t’, 60));
                        System.out.println(s1.substring(6));
                        System.out.println(s1.substring(3, 8));
                        System.out.println(s2.concat(“World”));
                        System.out.println(s2.replace(‘l’, ‘w’));
                        System.out.println(s3.toLowerCase());
                        System.out.println(s1.trim());

            }

}