Skip to content

Instantly share code, notes, and snippets.

@recoilme
Created July 29, 2015 08:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save recoilme/cd62ce572f8f653a4e18 to your computer and use it in GitHub Desktop.
Save recoilme/cd62ce572f8f653a4e18 to your computer and use it in GitHub Desktop.
//Строка
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