Is there a way to count how many specific characters are in a string?

Asked 2 years ago, Updated 2 years ago, 39 views

If you have the string a.b.c.d. in this string.I'd like to count how many there are. I'd like to know if I can find out without a repeat statement.

string java

2022-09-22 12:55

1 Answers

If you use StringUtils provided by Apache Library, int count = StringUtils.countMatches("a.b.c.d", "."); are available.

In the Spring framework, intocus = StringUtils.countOccurrencesOf("a.b.c.d", "."); is available.


2022-09-22 12:55

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.