Count function in python like java | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Count function in python like java

Hello Is there any method that count the given character in a string in java. Eg in python s="sololearn" print(s.count("l")) Output 2

24th Oct 2020, 3:24 PM
Varshith
Varshith - avatar
4 Answers
+ 2
I don't think there is some direct method available for this purpose. You must use some kind of loop to test that. This is one way. var s = "sololearn"; long charCount = s.chars() .filter(c->c=='l') .count(); System.out.print(charCount);
24th Oct 2020, 3:40 PM
Avinesh
Avinesh - avatar
+ 6
array.length : length is a final variable applicable for arrays. With the help of length variable, we can obtain the size of the array. string.length() : length() method is a final variable which is applicable for string objects. length() method returns the number of characters presents in the string. https://www.geeksforgeeks.org/length-vs-length-java/
24th Oct 2020, 3:29 PM
Galaxy-Coding (inactive)
Galaxy-Coding (inactive) - avatar
+ 2
s.length()
24th Oct 2020, 3:27 PM
Gordon
Gordon - avatar
0
Hello I am asking the count of a single character in the string.
24th Oct 2020, 3:32 PM
Varshith
Varshith - avatar