Skip to content

Commit 94049c0

Browse files
author
Devansh K Shukla
committed
add an if() block along with a condition
1 parent 83d6539 commit 94049c0

2 files changed

Lines changed: 44 additions & 32 deletions

File tree

.idea/workspace.xml

Lines changed: 40 additions & 31 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/main/java/io/github/dbc/DuplicateCharactersCounter.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@ public class DuplicateCharactersCounter {
1010
* @param string String to count duplicate characters.
1111
* @return Map with characters and their count.
1212
*/
13-
public Map<Character, Integer> countDuplicateCharacters(String string) {
13+
public Map<Character, Integer> countDuplicateCharacters(String string) throws IllegalArgumentException {
1414
HashMap<Character, Integer> map = new HashMap<>();
15+
if (string == null) {
16+
throw new IllegalArgumentException();
17+
}
1518
for (int i = 0; i < string.length(); i++) {
1619
char ch = string.charAt(i);
1720
if (map.containsKey(ch)) {

0 commit comments

Comments
 (0)