Advertisement
Guest User

Untitled

a guest
Mar 23rd, 2019
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. import java.io.FileInputStream;
  2. import java.io.FileNotFoundException;
  3. import java.util.ArrayList;
  4. import java.util.Scanner;
  5.  
  6. public class ArrayListBenchmark {
  7.  
  8. public ArrayList<Pair> arrayList = new ArrayList<Pair>();
  9.  
  10. public void FillList(String path) {
  11. FileInputStream inputStream = null;
  12. try {
  13. inputStream = new FileInputStream(path);
  14. } catch (FileNotFoundException ex) {
  15. System.out.println("Файл не найден");
  16. return;
  17. }
  18.  
  19. Scanner sc = new Scanner(inputStream, "UTF-8");
  20. while (sc.hasNext()) {
  21. String word = sc.next();
  22. if (word.length() < 3)
  23. continue;
  24. if (arrayList.contains(word))
  25. {
  26. int i = arrayList.indexOf(word);
  27. arrayList.get(i).countRepetition += 1;
  28. }
  29. else
  30. {
  31. arrayList.add(new Pair(word, 1));
  32. }
  33. }
  34. }
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement