Guest User

Untitled

a guest
Dec 18th, 2018
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.14 KB | None | 0 0
  1. import Sample; //その他必要なクラスをimport済
  2.  
  3. //--メインメソッド内--
  4. List<Sample> samples //へデータベースの全レコードを格納済
  5. String keyword //へ特定の文字列を格納済
  6.  
  7. samples = keyList(samples, keyword);
  8.  
  9. //--メインメソッドのブロック外に目的のメソッドを記述--
  10. public List<Sample> keyList(List<Sample> list, String keyword) {
  11. List<Sample> newList = list;
  12. for(Sample sample : list) {
  13. if (sample.指定のgetter().contains(keyword)) {
  14. newList.remove(sample);
  15. }
  16. }
  17. return newList;
  18. }
  19.  
  20. for(Sample sample : list) {
  21. ...
  22. newList.remove(sample);
  23. }
  24. }
  25.  
  26. List<Sample> newList = list;
  27.  
  28. List<Sample> newList = new ArrayList<>(list);
  29.  
  30. List<Sample> newList = new ArrayList<>(list);
  31. newList.removeIf(sample -> sample.指定のgetter().contains(keyword));
  32. return newList;
  33.  
  34. List<Sample> newList = new ArrayList<>(list);
  35. Iterator<Sample> ite = newList.iterator();
  36. while (ite.hasNext()) {
  37. Sample sample = ite.next();
  38. if (sample.指定のgetter().contains(keyword)) {
  39. ite.remove();
  40. }
  41. }
  42. return newList;
Add Comment
Please, Sign In to add comment