mirror of
https://bitbucket.org/Mattrixwv/javaclasses.git
synced 2025-12-07 07:23:57 -05:00
Added function to count occurrences of a char in a string
This commit is contained in:
@@ -1,11 +1,11 @@
|
||||
//src/main/java/mattrixwv/Algorithms.java
|
||||
//JavaClasses/src/main/java/mattrixwv/Algorithms.java
|
||||
//Matthew Ellison
|
||||
// Created: 03-02-19
|
||||
//Modified: 06-15-20
|
||||
//Modified: 07-27-20
|
||||
//This class holds many algorithms that I have found it useful to keep around
|
||||
//As such all of the functions in here are static and meant to be used as stand alone functions
|
||||
/*
|
||||
Copyright (C) 2019 Matthew Ellison
|
||||
Copyright (C) 2020 Matthew Ellison
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Lesser General Public License as published by
|
||||
@@ -849,4 +849,8 @@ public class Algorithms{
|
||||
String swappedString = new String(tempStr);
|
||||
return swappedString;
|
||||
}
|
||||
//This function returns the number of times the character occurs in the string
|
||||
public static long findNumOccurrence(String str, char c){
|
||||
return str.chars().filter(ch -> ch == c).count();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user