简体   繁体   English

Java:将Arraylist打印到输出文件?

[英]Java: Printing Arraylist to Output File?

EDIT: To test these cases, change sort and filter methods to the following: 编辑:要测试这些情况,请将排序和筛选方法更改为以下内容:

EXAMPLE SORT METHOD: 排序方法示例:

public void sortTitle() {
    Collections.sort(songs2, SongComparator.byTitle()); // now we have a sorted list
}

EXAMPLE FILTER METHOD (FOR STRING INPUT): 过滤器方法示例(用于字符串输入):

public void filterTitle(String s) {
    int n = 0;
    if (n == 0) {
        n++;
        for (Song song1 : songs2) {
            if ((!(((song1.title).contains(s))))) {
            itemsToRemove.add(song1);
            }
        }
        songs2.removeAll(itemsToRemove);
        itemsToRemove.clear();
    }
}

EXAMPLE FILTER METHOD (FOR INT INPUT): 过滤器方法示例(用于INT输入):

public void filterRank(Range r) {
    int n = 0;
    if (n == 0) {
        n++;
        for (Song song1 : songs2) {
            if (song1.rank > (r.getMax()) || (song1.rank) < (r.getMin())) {
                itemsToRemove.add(song1);
            }
        }
        songs2.removeAll(itemsToRemove);
        itemsToRemove.clear();
    }
}

TEST CASES: 测试用例:

Input strings should be like the following examples: 输入字符串应类似于以下示例:

sort:title

This input runs successfully until the line System.setOut(out); 此输入将成功运行,直到行System.setOut(out); in the main class, where it begins to print spaces and does not successfully print the collection. 在主类中,它开始打印空格,但未成功打印集合。 This may be because of a problem with the toString method in the SongCollection class. 这可能是由于SongCollection类中的toString方法存在问题。

artist:Paramore

or 要么

title:Misery Business

This input runs successfully through the entire program (the program does not terminate because the while loop does not terminate), except instead of printing the collection, a blank space is printed. 此输入在整个程序中成功运行(该程序不会终止,因为while循环不会终止),除了打印集合以外,还会打印空白。

ADDITIONAL DETAILS: 额外细节:

This question is a followup to a previous question I asked, since I have short time constraints on this project (it is due tomorrow). 这个问题是我之前提出的问题的跟进,因为我在这个项目上有很短的时间限制(将于明天到期)。 The primary problem I am experiencing with this is that the program is failing to output correctly, even though the methods and code in the main for printing seems logically sound. 我遇到的主要问题是,即使从逻辑上讲,用于打印的主程序中的方法和代码似乎正确,程序仍无法正确输出。

Printing arraylist into output file? 打印arraylist到输出文件?

For some reason, it takes an extraordinary amount of time for the ArrayLists to be printed to the output file, usually 20-30 minutes. 由于某些原因,将ArrayLists打印到输出文件要花费大量时间,通常需要20-30分钟。 However, this only happens with the sort methods or the filterTitle or filterArtist methods (methods that concern String inputs). 但是,这仅在sort方法或filterTitlefilterArtist方法(与String输入有关的方法)中发生。 When I run filterRank or filterYear , it runs perfectly fine. 当我运行filterRankfilterYear ,它运行得很好。

When I print the song2 ArrayList directly from the filter methods, the only thing that is printed is [] , which means the ArrayList is empty, but it shouldn't be? 当我直接从过滤器方法打印song2 ArrayList ,唯一打印的是[] ,这意味着ArrayList为空,但不是吗? And the filterRank and filterYear methods still work regardless of this. 而且filterRankfilterRankfilterYear方法仍然有效。 Somehow I think it's related, though. 我以某种方式认为这是相关的。

Input file can be found here: http://staff.rentonschools.us/hhs/ap-comp-science/projects/download/agazillionsongs.txt?id=223098 输入文件可以在这里找到: http : //staff.rentonschools.us/hhs/ap-comp-science/projects/download/agazillionsongs.txt?id=223098

Full code for compilation: 完整的编译代码:

   import java.io.*;
   import java.io.File;
   import java.io.FileNotFoundException;
   import java.util.*;
   import java.util.Comparator;
   import java.util.Scanner;
   import java.util.StringTokenizer;

public class GazillionSongs {
   public static void main(String[] args) throws FileNotFoundException, IOException {
      System.out.println("Welcome to Java Song Collection!"); // greets the user
      System.out
      .println("This program sorts and filters large databases of popular songs."); // explains purpose of program
      System.out
      .println("This program is able to filter and sort by year, artist, title and rank.");
      System.out
      .println("Please enter a file that contains a database you wish to filter or sort. (i.e, alistofsongs.txt)"); // sample file = agazillionsongs.txt
      Scanner fileInput = new Scanner(System.in); //Scanner which accepts filename
      String filename = fileInput.nextLine();

      File f = new File(filename); //creates file from input
      /*error check for file here*/
      Scanner fileScanner = new Scanner(f); //inputs data from file

      ArrayList<Song> songs = new ArrayList<Song>();
      while ((fileScanner.hasNextLine())) {
         songs.add(Song.parse(fileScanner.nextLine()));
      }

      System.out
      .println("Please select which commands you would like to use for the program.");
      System.out
      .println("Please format your command like the following example: year:<year(s)> rank:<rank(s)> artist:<artist> title:<title> sortBy:<field>");
      System.out.println();
      System.out.println("You may pick any number of commands you want.");
      System.out
      .println("For years and rank, you may select a range of years or ranks.");
      System.out
      .println("For artists and titles, you may enter a partial name or title.");
      System.out.println("i.e, year:1983 rank:1");
      Scanner input = new Scanner(System.in);

      while (input.hasNextLine()) {
         int n = 0;
         SongCollection collection = new SongCollection(songs);
         String inputType = input.nextLine();
         String delims = "[ ]";
         String[] tokens = inputType.split(delims);
         for (int i = 0; i < tokens.length; i++) {
            n = 0;
            if (n == 0) {
               if ((tokens[i]).contains("year:")) {
                  collection.filterYear(Range.parse(tokens[i]));
                  n = 1;
               }// end of year loop
               if ((tokens[i]).contains("rank:")) {
                  collection.filterRank(Range.parse(tokens[i]));
                  n = 1;
               }// end of rank
               if ((tokens[i]).contains("artist:")) {
                  collection.filterArtist(tokens[i]);
                  n = 1;
               }// end of artist
               if ((tokens[i]).contains("title:")) {
                  collection.filterTitle(tokens[i]);
                  n = 1;
               }// end of title
               if ((tokens[i]).contains("sort:")) {
                     if ((tokens[i]).contains("title")) {
                        collection.sortTitle();
                        n = 1;
                     }// end of sort title
                     if ((tokens[i]).contains("artist")) {
                        collection.sortArtist();
                        n = 1;
                     }// end of sort artist
                     if ((tokens[i]).contains("rank")) {
                        collection.sortRank();
                        n = 1;
                     }// end of sort rank
                     if ((tokens[i]).contains("year")) {
                        collection.sortYear();
                        n = 1;
                     }// end of sort year
               }//end of sort
            }// end of for loop

         }// end of input.hasNextline loop
         final PrintStream console = System.out; //saves original System.out
         File outputFile = new File("output.txt"); //output file
         PrintStream out = new PrintStream(new FileOutputStream(outputFile)); //new FileOutputStream
         System.setOut(out); //changes where data will be printed
         System.out.println(collection.toString());

         System.setOut(console); //changes output to print back to console
         Scanner outputFileScanner = new Scanner(outputFile); //inputs data from file
         while ((outputFileScanner.hasNextLine())) { //while the file still has data
            System.out.println(outputFileScanner.nextLine()); //print
         }
         outputFileScanner.close();
         out.close();
      }
   }// end of main
}// end of class

class Song{
   public enum Order {Year, Rank, Title, Artist}
   public int year;
   public int rank;
   public String artist;
   public String title;

   public static Song parse(String s) {
      Song instance = new Song();
      StringTokenizer tokenizer = new StringTokenizer(s, "\t");
      instance.year = Integer.parseInt(tokenizer.nextToken());
      instance.rank = Integer.parseInt(tokenizer.nextToken());
      instance.artist = (tokenizer.nextToken());
      instance.title = (tokenizer.nextToken());
      return instance;
   }

   public int getYear() {
      return year;
   }

   public int getRank() {
      return rank;
   }

   public String getArtist() {
      return artist;
   }

   public String getTitle() {
      return title;

   }

   public String toString() {
      String output = "\n\nYear = " + year + "\nRank = " + rank + "\nArtist = "
            + artist + "\nTitle = " + title;
      return output;
   }

}
class Range {
   private int min;
   private int max;

   public Range() {
      System.out.println("Please wait.");
   }

   public static Range parse(String s) {
      Range instance = new Range(); // instance is created here so object
                              // variables may be accessed
      String field; // String to contain deleted part of user input
      StringTokenizer tokenizer = new StringTokenizer(s, "-");
      StringTokenizer tokenizer2 = new StringTokenizer(s, ":");// for separating "field:" from the
                                                   // other part of the String
      if (s.contains(":")) { // this deletes the "field:" of the user input so
                        // it does not interfere with the parsing
         field = (tokenizer2.nextToken());
         s = s.replace(field, "");
         s = s.replace(":", "");
      }
      if (s.contains("-")) {
         instance.min = Integer.parseInt(tokenizer.nextToken());
         instance.max = Integer.parseInt(tokenizer.nextToken());

      } else if (!(s.contains("-"))) {
         {
            instance.min = Integer.parseInt(s);
            instance.max = Integer.parseInt(s);
         }
      }
      System.out.println("Range max = " + instance.max);
      System.out.println("Range min = " + instance.min);
      return instance;
   }

   public boolean contains(int n) {
      if (n > min && n < max) { //if the number is contained in the range, method returns true.
         return true;
      } else if (n == min && n == max) {
         return true;
      } else {
         return false;
      }
   }

   public int getMin() {
      return min;
   }

   public int getMax() {
      return max;
   }
}
class SongCollection {
   ArrayList<Song> songs2;
   ArrayList<Song> itemsToRemove = new ArrayList<Song>(); // second collection
                                             // for items to
                                             // remove
   public SongCollection(ArrayList<Song> songs) { // constructor for SongCollection
      System.out.println("Test");
      this.songs2 = songs;
      }
   public void filterYear(Range r) {
      int n = 0;
      if (n == 0) {
         System.out.println("Program is processing.");
         n++;
         for (Song song1 : songs2) {
            if (song1.year > (r.getMax()) || (song1.year) < (r.getMin())) {
               itemsToRemove.add(song1);
            }
         }
         songs2.removeAll(itemsToRemove);
         itemsToRemove.clear();
      }
      System.out.println(songs2);
   }

   public void filterRank(Range r) {
      int n = 0;
      if (n == 0) {
         System.out.println("Program is processing.");
         n++;
         for (Song song1 : songs2) {
            if (song1.rank > (r.getMax()) || (song1.rank) < (r.getMin())) {
               itemsToRemove.add(song1);
            }
         }
         songs2.removeAll(itemsToRemove);
         itemsToRemove.clear();
      }
      System.out.println(songs2);
   }

   public void filterArtist(String s) {
      int n = 0;
      if (n == 0) {
         System.out.println("Program is processing.");
         n++;
         for (Song song1 : songs2) {
            if ((!(((song1.artist).contains(s))))) {
               itemsToRemove.add(song1);
            }
         }
         songs2.removeAll(itemsToRemove);
         itemsToRemove.clear();
      }
      System.out.println(songs2);
   }

   public void filterTitle(String s) {
      int n = 0;
      if (n == 0) {
         System.out.println("Program is processing.");
         n++;
         for (Song song1 : songs2) {
            if ((!(((song1.title).contains(s))))) {
            itemsToRemove.add(song1);
            }
         }
         songs2.removeAll(itemsToRemove);
         itemsToRemove.clear();
      }
      System.out.println(songs2);
   }

   public void sortTitle() {
        Collections.sort(songs2, SongComparator.byTitle()); // now we have a sorted list
        System.out.println(songs2);
      }
   public void sortRank() {
        Collections.sort(songs2, SongComparator.byRank()); // now we have a sorted list
        System.out.println(songs2);
      }
   public void sortArtist() {
        Collections.sort(songs2, SongComparator.byArtist()); // now we have a sorted list
        System.out.println(songs2);
      }
   public void sortYear() {
        Collections.sort(songs2, SongComparator.byYear()); // now we have a sorted list
        System.out.println(songs2);
      }
   public String toString() {
      String result = "";
      for (int i = 0; i < songs2.size(); i++) {
         result += " " + songs2.get(i);
      }

      return result;

   }
}
class SongComparator implements Comparator<Song> {
   public enum Order{
      YEAR_SORT, RANK_SORT, ARTIST_SORT, TITLE_SORT
   }
   private Order sortingBy;
   public SongComparator(Order sortingBy){
      this.sortingBy = sortingBy;
   }
   public static SongComparator byTitle() {
       return new SongComparator(SongComparator.Order.TITLE_SORT);
   }
   public static SongComparator byYear() {
       return new SongComparator(SongComparator.Order.YEAR_SORT);
   }
   public static SongComparator byArtist() {
       return new SongComparator(SongComparator.Order.ARTIST_SORT);
   }
   public static SongComparator byRank() {
       return new SongComparator(SongComparator.Order.RANK_SORT);
   }

   @Override
   public int compare(Song song1, Song song2) {
      switch (sortingBy) {
      case YEAR_SORT:
         return Integer.compare(song1.year, song2.year);
      case RANK_SORT:
         return Integer.compare(song1.rank, song2.rank);
      case ARTIST_SORT:
         return song1.artist.compareTo(song2.artist);
      case TITLE_SORT:
         return song1.title.compareTo(song2.title);
      }
      throw new RuntimeException(
            "Practically unreachable code, can't be thrown");
   }

}

I tried to run this code and it works fine and fast. 我试图运行此代码,它可以正常且快速地运行。 I am using file you posted and as you can see, test value for searching is "year:1983 sort:title". 我正在使用您发布的文件,并且您可以看到,用于搜索的测试值为“ year:1983 sort:title”。 I also simplified it by removing while-cycle and user-input filename and filter string, so anyone can easily reproduce it. 我还通过删除while循环以及用户输入的文件名和过滤器字符串简化了它,因此任何人都可以轻松地重现它。

If you want to help, I need to know, how to reproduce that 20-30 minute outputing to file. 如果您想提供帮助,我需要知道如何将20到30分钟的输出重现到文件中。 :

import java.io.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.util.*;
import java.util.Comparator;
import java.util.Scanner;
import java.util.StringTokenizer;

public class GazillionSongs {

    public static void main(String[] args) throws FileNotFoundException, IOException {
        Scanner input = new Scanner(System.in);
        System.out.println("Welcome to Java Song Collection!"); // greets the user
        System.out
                .println("This program sorts and filters large databases of popular songs."); // explains purpose of program
        System.out
                .println("This program is able to filter and sort by year, artist, title and rank.");
        System.out
                .println("Please enter a file that contains a database you wish to filter or sort. (i.e, alistofsongs.txt)"); // sample file = agazillionsongs.txt

        File f = new File("agazillionsongs.txt"); //creates file from input
      /*error check for file here*/
        Scanner fileScanner = new Scanner(f); //inputs data from file

        List<Song> songs = new ArrayList<Song>();
        while ((fileScanner.hasNextLine())) {
            Song song = Song.parse(fileScanner.nextLine());
            songs.add(song);
        }

        System.out
                .println("Please select which commands you would like to use for the program.");
        System.out
                .println("Please format your command like the following example: year:<year(s)> rank:<rank(s)> artist:<artist> title:<title> sortBy:<field>");
        System.out.println();
        System.out.println("You may pick any number of commands you want.");
        System.out
                .println("For years and rank, you may select a range of years or ranks.");
        System.out
                .println("For artists and titles, you may enter a partial name or title.");
        System.out.println("i.e, year:1983 rank:1");

        int n = 0;
        SongCollection collection = new SongCollection(songs);
        String inputType = "year:1983 sort:title";
        String delims = "[ ]";
        String[] tokens = inputType.split(delims);
        for (int i = 0; i < tokens.length; i++) {
            n = 0;
            if (n == 0) {
                if ((tokens[i]).contains("year:")) {
                    collection.filterYear(Range.parse(tokens[i]));
                    n = 1;
                }// end of year loop
                if ((tokens[i]).contains("rank:")) {
                    collection.filterRank(Range.parse(tokens[i]));
                    n = 1;
                }// end of rank
                if ((tokens[i]).contains("artist:")) {
                    collection.filterArtist(tokens[i]);
                    n = 1;
                }// end of artist
                if ((tokens[i]).contains("title:")) {
                    collection.filterTitle(tokens[i]);
                    n = 1;
                }// end of title
                if ((tokens[i]).contains("sort:")) {
                    if ((tokens[i]).contains("title")) {
                        collection.sortTitle();
                        n = 1;
                    }// end of sort title
                    if ((tokens[i]).contains("artist")) {
                        collection.sortArtist();
                        n = 1;
                    }// end of sort artist
                    if ((tokens[i]).contains("rank")) {
                        collection.sortRank();
                        n = 1;
                    }// end of sort rank
                    if ((tokens[i]).contains("year")) {
                        collection.sortYear();
                        n = 1;
                    }// end of sort year
                }//end of sort
            }// end of for loop

        }// end of input.hasNextline loop
        final PrintStream console = System.out; //saves original System.out
        File outputFile = new File("output.txt"); //output file
        PrintStream out = new PrintStream(new FileOutputStream(outputFile)); //new FileOutputStream
        System.setOut(out); //changes where data will be printed
        System.out.println(collection.toString());

        System.setOut(console); //changes output to print back to console
        Scanner outputFileScanner = new Scanner(outputFile); //inputs data from file
        while ((outputFileScanner.hasNextLine())) { //while the file still has data
            System.out.println(outputFileScanner.nextLine()); //print
        }
        outputFileScanner.close();
        out.close();
    }
}// end of main

class Song {

    public enum Order {

        Year, Rank, Title, Artist
    }
    public int year;
    public int rank;
    public String artist;
    public String title;

    public static Song parse(String s) {
        Song instance = new Song();
        StringTokenizer tokenizer = new StringTokenizer(s, "\t");
        instance.year = Integer.parseInt(tokenizer.nextToken());
        instance.rank = Integer.parseInt(tokenizer.nextToken());
        instance.artist = (tokenizer.nextToken());
        instance.title = (tokenizer.nextToken());
        return instance;
    }

    public int getYear() {
        return year;
    }

    public int getRank() {
        return rank;
    }

    public String getArtist() {
        return artist;
    }

    public String getTitle() {
        return title;

    }

    public String toString() {
        String output = "\n\nYear = " + year + "\nRank = " + rank + "\nArtist = "
                + artist + "\nTitle = " + title;
        return output;
    }

}

class Range {

    private int min;
    private int max;

    public Range() {
        System.out.println("Please wait.");
    }

    public static Range parse(String s) {
        Range instance = new Range(); // instance is created here so object
        // variables may be accessed
        String field; // String to contain deleted part of user input
        StringTokenizer tokenizer = new StringTokenizer(s, "-");
        StringTokenizer tokenizer2 = new StringTokenizer(s, ":");// for separating "field:" from the
        // other part of the String
        if (s.contains(":")) { // this deletes the "field:" of the user input so
            // it does not interfere with the parsing
            field = (tokenizer2.nextToken());
            s = s.replace(field, "");
            s = s.replace(":", "");
        }
        if (s.contains("-")) {
            instance.min = Integer.parseInt(tokenizer.nextToken());
            instance.max = Integer.parseInt(tokenizer.nextToken());

        } else if (!(s.contains("-"))) {
            {
                instance.min = Integer.parseInt(s);
                instance.max = Integer.parseInt(s);
            }
        }
        System.out.println("Range max = " + instance.max);
        System.out.println("Range min = " + instance.min);
        return instance;
    }

    public boolean contains(int n) {
        if (n > min && n < max) { //if the number is contained in the range, method returns true.
            return true;
        } else if (n == min && n == max) {
            return true;
        } else {
            return false;
        }
    }

    public int getMin() {
        return min;
    }

    public int getMax() {
        return max;
    }
}

class SongCollection {

    List<Song> songs2;
    List<Song> itemsToRemove = new ArrayList<Song>(); // second collection
    // for items to
    // remove

    public SongCollection(List<Song> songs) { // constructor for SongCollection
        System.out.println("Test");
        this.songs2 = songs;
    }

    public void filterYear(Range r) {
        int n = 0;
        if (n == 0) {
            System.out.println("Program is processing.");
            n++;
            for (Song song1 : songs2) {
                if (song1.year > (r.getMax()) || (song1.year) < (r.getMin())) {
                    itemsToRemove.add(song1);
                }
            }
            songs2.removeAll(itemsToRemove);
            itemsToRemove.clear();
        }
        System.out.println(songs2);
    }

    public void filterRank(Range r) {
        int n = 0;
        if (n == 0) {
            System.out.println("Program is processing.");
            n++;
            for (Song song1 : songs2) {
                if (song1.rank > (r.getMax()) || (song1.rank) < (r.getMin())) {
                    itemsToRemove.add(song1);
                }
            }
            songs2.removeAll(itemsToRemove);
            itemsToRemove.clear();
        }
        System.out.println(songs2);
    }

    public void filterArtist(String s) {
        int n = 0;
        if (n == 0) {
            System.out.println("Program is processing.");
            n++;
            for (Song song1 : songs2) {
                if ((!(((song1.artist).contains(s))))) {
                    itemsToRemove.add(song1);
                }
            }
            songs2.removeAll(itemsToRemove);
            itemsToRemove.clear();
        }
        System.out.println(songs2);
    }

    public void filterTitle(String s) {
        int n = 0;
        if (n == 0) {
            System.out.println("Program is processing.");
            n++;
            for (Song song1 : songs2) {
                if ((!(((song1.title).contains(s))))) {
                    itemsToRemove.add(song1);
                }
            }
            songs2.removeAll(itemsToRemove);
            itemsToRemove.clear();
        }
        System.out.println(songs2);
    }

    public void sortTitle() {
        Collections.sort(songs2, SongComparator.byTitle()); // now we have a sorted list
        System.out.println(songs2);
    }

    public void sortRank() {
        Collections.sort(songs2, SongComparator.byRank()); // now we have a sorted list
        System.out.println(songs2);
    }

    public void sortArtist() {
        Collections.sort(songs2, SongComparator.byArtist()); // now we have a sorted list
        System.out.println(songs2);
    }

    public void sortYear() {
        Collections.sort(songs2, SongComparator.byYear()); // now we have a sorted list
        System.out.println(songs2);
    }

    public String toString() {
        String result = "";
        for (int i = 0; i < songs2.size(); i++) {
            result += " " + songs2.get(i);
        }

        return result;

    }
}

class SongComparator implements Comparator<Song> {

    public enum Order {

        YEAR_SORT, RANK_SORT, ARTIST_SORT, TITLE_SORT
    }
    private Order sortingBy;

    public SongComparator(Order sortingBy) {
        this.sortingBy = sortingBy;
    }

    public static SongComparator byTitle() {
        return new SongComparator(SongComparator.Order.TITLE_SORT);
    }

    public static SongComparator byYear() {
        return new SongComparator(SongComparator.Order.YEAR_SORT);
    }

    public static SongComparator byArtist() {
        return new SongComparator(SongComparator.Order.ARTIST_SORT);
    }

    public static SongComparator byRank() {
        return new SongComparator(SongComparator.Order.RANK_SORT);
    }

    @Override
    public int compare(Song song1, Song song2) {
        switch (sortingBy) {
            case YEAR_SORT:
                return Integer.compare(song1.year, song2.year);
            case RANK_SORT:
                return Integer.compare(song1.rank, song2.rank);
            case ARTIST_SORT:
                return song1.artist.compareTo(song2.artist);
            case TITLE_SORT:
                return song1.title.compareTo(song2.title);
        }
        throw new RuntimeException(
                "Practically unreachable code, can't be thrown");
    }

}

EDIT : 编辑:

Question: 题:


title:Misery Business

This input runs successfully through the entire program (the program does not terminate because the while loop does not terminate), except instead of printing the collection, a blank space is printed. 此输入在整个程序中成功运行(该程序不会终止,因为while循环不会终止),除了打印集合以外,还会打印空白。


Yes, because in your method, you are testing, if it contains title:Misery Business not Misery Business . 是的,因为您的方法正在测试中是否包含title:Misery Business而不是Misery Business

First of all, you cant use that tokenizer for anything, that contains space. 首先,您不能将令牌生成器用于任何包含空间的东西。 But for one-word only, you can change it as following : 但是,仅对于一个单词,您可以将其更改为以下内容:

Tested and working for title:Misery : 经过测试并为title:Misery工作title:Misery

public void filterTitle(String s) {
    int n = 0;
    s = s.split(":")[1];
    if (n == 0) {
        System.out.println("Program is processing.");
        n++;
        for (Song song1 : songs2) {
            if (song1.title.contains(s) == false) {
                itemsToRemove.add(song1);
            }
        }
        songs2.removeAll(itemsToRemove);
        itemsToRemove.clear();
    }
    System.out.println(songs2);
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM