JAVA Program to Perform String Manipulation Functions

JAVA Program to Perform String Manipulation Functions:


 class StringManipulation
 {
  public static void main(String args[])
  {
  StringBuffer str = new StringBuffer("Object language");
  System.out.println("Original String : "+ str);
  System.out.println("Length of string " + str.length());

  for(int i= 0; i<str.length();i++)
  {
    int p=i+1;
    System.out.println("Character at position : "+ p + " is "+ str.charAt(i));
  }

   String aString = new String(str.toString());
   int pos = aString.indexOf(" language");
   str.insert(pos," Oriented");
   System.out.println("Modified string : "+str);

   str.setCharAt(6,'-');
   System.out.println("String now : "+str);
   str.append(" improves security.");
   System.out.println("Appented string : " +str);

  }
  }

OUTPUT:

Original String : Object language
Length of string 15
Character at position : 1 is O
Character at position : 2 is b
Character at position : 3 is j
Character at position : 4 is e
Character at position : 5 is c
Character at position : 6 is t
Character at position : 7 is
Character at position : 8 is l
Character at position : 9 is a
Character at position : 10 is n
Character at position : 11 is g
Character at position : 12 is u
Character at position : 13 is a
Character at position : 14 is g
Character at position : 15 is e
Modified string : Object Oriented language
String now : Object-Oriented language
Appended string : Object-Oriented language improves security.



Leave a Reply

Your email address will not be published. Required fields are marked *

eleven + 4 =