Get Character from String

In this example we will see that how to convert string to array of character and retrieve elements from that character array one by one.


 
Ads

Get Character from String

     

In this example we will see that how to convert string to array of character and retrieve elements from that character array one by one.


Description of the code:
1.
First declare and initialize string.
2. use method toCharArray() to convert string to character array.
3. Retrieve character from character array one by one using for loop.
 

 

 

 

Here is the code of GetCharFromString

public class GetCharFromString{
  
  public void convertStringToChar() {
  String str = "ANUSMITA";
  char[] ch = str.toCharArray();
  for (char c : ch)
  System.out.println(c);
  }
  public static void main(String[] args) {
  new GetCharFromString().convertStringToChar();
  }
}

 

Output will be displayed as:

 

Download Source Code

 

Advertisements

Share on Google+Share on Google+

Get Character from String

Posted on: October 23, 2008 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Advertisements

Ads
 

Discuss: Get Character from String  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:1
Slindile
August 17, 2011
J2ME

hi, I am a beginner in J2ME and i just need a simple statement to display a name entered by the user in the text field.

Ads

 

Ads