File tree Expand file tree Collapse file tree
main/java/com/baeldung/algorithms/string
test/java/com/baeldung/algorithms/string Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ package com .baeldung .algorithms .string ;
2+
3+ public class EnglishAlphabetLetters {
4+
5+ public static boolean checkStringForAllTheLetters (String input ) {
6+ boolean [] visited = new boolean [26 ];
7+
8+ int index = 0 ;
9+
10+ for (int id = 0 ; id < input .length (); id ++) {
11+ if ('a' <= input .charAt (id ) && input .charAt (id ) <= 'z' ) {
12+ index = input .charAt (id ) - 'a' ;
13+ } else if ('A' <= input .charAt (id ) && input .charAt (id ) <= 'Z' ) {
14+ index = input .charAt (id ) - 'A' ;
15+ }
16+ visited [index ] = true ;
17+ }
18+
19+ for (int id = 0 ; id < 26 ; id ++) {
20+ if (!visited [id ]) {
21+ return false ;
22+ }
23+ }
24+ return true ;
25+ }
26+
27+ public static boolean checkStringForAllLetterUsingStream (String input ) {
28+ long c = input .toLowerCase ().chars ().filter (ch -> ch >= 'a' && ch <= 'z' ).distinct ().count ();
29+ return c == 26 ;
30+ }
31+
32+ public static void main (String [] args ) {
33+ checkStringForAllLetterUsingStream ("intit" );
34+ }
35+ }
Original file line number Diff line number Diff line change 1+ package com .baeldung .algorithms .string ;
2+
3+ import org .junit .jupiter .api .Assertions ;
4+ import org .junit .jupiter .api .Test ;
5+
6+ public class EnglishAlphabetLettersUnitTest {
7+
8+ @ Test
9+ void givenString_whenContainsAllCharacter_thenTrue () {
10+ String input = "Farmer jack realized that big yellow quilts were expensive" ;
11+ Assertions .assertTrue (EnglishAlphabetLetters .checkStringForAllTheLetters (input ));
12+ }
13+
14+ @ Test
15+ void givenString_whenContainsAllCharacter_thenUsingStreamExpectTrue () {
16+ String input = "Farmer jack realized that big yellow quilts were expensive" ;
17+ Assertions .assertTrue (EnglishAlphabetLetters .checkStringForAllLetterUsingStream (input ));
18+ }
19+
20+ }
You can’t perform that action at this time.
0 commit comments