Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Comments

Close side panel

Feature#1

Open
victortwin wants to merge 3 commits intojava-online-course:masterjava-online-course/java-collections-template:masterfrom
victortwin:featurevictortwin/java-collections-template:featureCopy head branch name to clipboard
Open

Feature#1
victortwin wants to merge 3 commits intojava-online-course:masterjava-online-course/java-collections-template:masterfrom
victortwin:featurevictortwin/java-collections-template:featureCopy head branch name to clipboard

Conversation

@victortwin
Copy link

No description provided.

@Override
public List<String> getWords(String text) {
return new ArrayList<>();
return new ArrayList<>(Arrays.asList(text.split("\\W+")));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Можно просто Arrays.asList(text.split("\\W+"))

@Override
public List<String> sortWordsByLength(String text, Direction direction) {
return new ArrayList<>();
ArrayList<String> allWords = (ArrayList<String>) getWords(text);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем явно указывать ArrayList

List<String> listOfWords = new ArrayList<>();
String [] arrayOfWords = text.split("\\W+");
Arrays.stream(arrayOfWords).forEach(listOfWords::add);
return listOfWords;
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Stream.of(text.split("\W+").collect(Collectors.toList());

Map<String, Integer> countWordsRepetitionsMap = new LinkedHashMap<>();
for (String s : allWords) {
int repetitionCounter = Collections.frequency(allWords, s);
countWordsRepetitionsMap.put(s, repetitionCounter);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

У тебя же это будет вызываться для каждой копии слова в листе слов?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Да, получается решение более медленное с точки зрения времени выполнения, но более быстрое для программиста :)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Наверное, надо было использовать список уникальных слов, а частоту их употребления собирать из списка всех слов.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

Morty Proxy This is a proxified and sanitized view of the page, visit original site.