-
-
Save recoilme/cd62ce572f8f653a4e18 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Строка | |
String s = "adsdasd"; | |
//Ридер | |
Reader reader = new StringReader(s); | |
//Сет для посчитанных букв | |
Set<Character> set = new HashSet<>(); | |
int size = Math.min(s.length(),8192); | |
try { | |
Character ch = null; | |
//Читаем по 8192 букве | |
//Делаем множество букв, которые есть в строке | |
char[] chars = new char[size]; | |
for(int len; (len = reader.read(chars)) > 0;) { | |
for(int i=0;i<chars.length;i++) { | |
set.add(chars[i]); | |
} | |
} | |
//перебираем сет | |
Iterator<Character> iterator = set.iterator(); | |
while (iterator.hasNext()) { | |
ch = iterator.next(); | |
int count = 0; | |
reader = new StringReader(s); | |
char[] buf = new char[1]; | |
for(int len; (len = reader.read(buf)) > 0;) { | |
if (buf[0] == ch) count++; | |
else continue; | |
} | |
System.out.println(ch + ":" + count); | |
} | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} finally { | |
try { | |
reader.close(); | |
} catch (IOException e) { | |
e.printStackTrace(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment