• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

occurence of char in a string

 
suman deb
Ranch Hand
Posts: 54
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

how to find out the occurence of each char in a string? e.g.

for the string "HELLO" , the required out put is--

H - 1
E - 1
L - 2
o - 1

please help
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You could try with String.indexOf(int ch, int fromIndex), looping through the whole String.
 
Allan Morris
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi, a map is a good data structure, pairing each character to a count. You can do it like this using the Collections framework:


[ September 05, 2006: Message edited by: Allan Morris ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic