employer cover photo
employer logo

Pregunta de entrevista de Hortonworks

Write a program to count words in a string?

Respuesta de la entrevista

Anónimo

8 jul 2018

void countWords(String text) { Map wordCount = new HashMap(); List words = Arrays.asList(text.split(" ")); for (String word : words) { if (wordCount.containsKey(word)) { wordCount.put(word, wordCount.get(word) + 1); } else { wordCount.put(word, 1); } } }