This week's book giveaways are in the Java EE and JavaScript forums.
We're giving away four copies each of The Java EE 7 Tutorial Volume 1 or Volume 2(winners choice) and jQuery UI in Action and have the authors on-line!
See this thread and this one for details.
The moose likes Beginning Java and the fly likes How to Split and count the character Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "How to Split and count the character" Watch "How to Split and count the character" New topic
Author

How to Split and count the character

athi ram
Greenhorn

Joined: Feb 28, 2011
Posts: 6
hi sir

the String s = "aabbcccf";

i want output

String s = "2a2b3cf";

i don't know which method is suitable...

please help me
Vinoth Kumar Kannan
Ranch Hand

Joined: Aug 19, 2009
Posts: 276

I guess, you'll have to do manual iterating over every single character in the String and then finally form your final String...


OCPJP 6
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38466
    
  23
Welcome to the Ranch

You will have to write down on paper what you intend to do; then you can covert it to code.
athi ram
Greenhorn

Joined: Feb 28, 2011
Posts: 6


successfully executed....
any other way please inform me
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38466
    
  23
You aren't supposed to print "a appears 4 times". You are supposed to have a String with 4a at the beginning.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19674
    
  18

Please UseCodeTags next time. I've added them for you this time. And also add some indentation; another thing I've added.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Split and count the character