Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import Sample; //その他必要なクラスをimport済
- //--メインメソッド内--
- List<Sample> samples //へデータベースの全レコードを格納済
- String keyword //へ特定の文字列を格納済
- samples = keyList(samples, keyword);
- //--メインメソッドのブロック外に目的のメソッドを記述--
- public List<Sample> keyList(List<Sample> list, String keyword) {
- List<Sample> newList = list;
- for(Sample sample : list) {
- if (sample.指定のgetter().contains(keyword)) {
- newList.remove(sample);
- }
- }
- return newList;
- }
- for(Sample sample : list) {
- ...
- newList.remove(sample);
- }
- }
- List<Sample> newList = list;
- List<Sample> newList = new ArrayList<>(list);
- List<Sample> newList = new ArrayList<>(list);
- newList.removeIf(sample -> sample.指定のgetter().contains(keyword));
- return newList;
- List<Sample> newList = new ArrayList<>(list);
- Iterator<Sample> ite = newList.iterator();
- while (ite.hasNext()) {
- Sample sample = ite.next();
- if (sample.指定のgetter().contains(keyword)) {
- ite.remove();
- }
- }
- return newList;
Add Comment
Please, Sign In to add comment