Skip to content

Commit ac158a4

Browse files
Replaced for loop with enhanced for
1 parent 8028c9a commit ac158a4

File tree

1 file changed

+3
-3
lines changed
  • data-structures/src/main/java/com/baeldung/trie

1 file changed

+3
-3
lines changed

data-structures/src/main/java/com/baeldung/trie/Trie.java

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@ class Trie {
1010
void insert(String word) {
1111
TrieNode current = root;
1212

13-
for (int i = 0; i < word.length(); i++) {
14-
current = current.getChildren().computeIfAbsent(word.charAt(i), c -> new TrieNode());
13+
for (char l : word.toCharArray()) {
14+
current = current.getChildren().computeIfAbsent(l, c -> new TrieNode());
1515
}
1616
current.setEndOfWord(true);
1717
}
@@ -59,4 +59,4 @@ private boolean delete(TrieNode current, String word, int index) {
5959
}
6060
return false;
6161
}
62-
}
62+
}

0 commit comments

Comments
 (0)