-3

Can anyone help me to write code that find how many characters string has.

Nyunus
  • 1
  • 3

2 Answers2

1

All you need is - int len = yourString.length();

Raman Shrivastava
  • 2,923
  • 15
  • 26
0

StringUtils should provide you with something that you are looking for:

       int count = StringUtils.countMatches("haahaahaa", "a");
       System.out.println(count);
The Roy
  • 2,178
  • 1
  • 17
  • 33
  • So just for a small task like this you will add 3rd party jar? – Raman Shrivastava Apr 17 '16 at 15:26
  • The person who asked the question did not ask for an algorithm here and I don't see a reason why you need to reinvent the wheel everytime. Assume that for such common functions apache thought what sort of standard utils to provide. – The Roy Apr 17 '16 at 15:33
  • This isn't the answer any more.. Nyunus edited his question – Klatschen Apr 18 '16 at 08:02