Java Basic Problems

Java:How to insert a word in the middle and at the last position of a String.

Here is the solution to insert a word in the middle and at the last position of a string.

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”);

System.out.println(“Modified string:”+str);
System.out.println(“String now:”+str);
str.append(“improves security”);
System.out.println(“Appended string:”+str);


 insert word in the middle of string

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s