Java: How to find out the position of a character in a String using StringBuffer.

Here, I want to share you a solution to find out the position of  characters  in a String using StringBuffer  in  java.

 

 

Code Example:

 

 

class StringManipulation

{

 public static void main(String args[])

{

StringBuffer str= new StringBuffer(“Software Engineering”);

System.out.println(“\n”);

System.out.println(“Original String:”+str);

System.out.println(“\n”);

System.out.println(“length of String:”+str.length());

System.out.println(“\n”);

 for(int i=0;i<str.length();i++)

{

int p=i+1;

System.out.println(“Character at position:”+p+”:is:”+str.charAt(i));

 

}

System.out.println(“\n”);

}

}

OUTPUT:

Character Position in a string java

About these ads

Leave a Reply

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

WordPress.com Logo

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

Twitter picture

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

Facebook photo

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

Google+ photo

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

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 293 other followers