程序填空题:the Bands
The following program reads a lot of lines of names, each name represents an artist or a band.
The name of a band begins with "the", that is easy to be recognized.
The last word in that line is the nationality of the band or the artist.
Our job it to summarize all the nationalities of all the bands, then print them.
For example, for input:
```
Taylor Swift U.S.
the Beattles U.K.
the Dynasty Tang China
the May Flower China
```
The output should be:
```
China
U.K.
```
Now, fill in the blanks below:
```Java
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
ArrayList lst = new ArrayList();
while ( in.hasNextLine() ) {
String line = in.nextLine();
lst.add(line.split(" "));
}
Set ret = lst.stream()
.filter(@@[x->x[0].equals("the")](2))
.map(@@[x->x[x.length-1]](2))
.collect(Collectors.@@[toSet()](1));
ArrayList r = new ArrayList(ret);
Collections.sort(r);
for ( String s: r ) {
System.out.println(s);
}
in.close();
}
}
```
答案:
第1空:x->x[0].equals("the")
第2空:x->x[x.length-1]
第3空:toSet()
The name of a band begins with "the", that is easy to be recognized.
The last word in that line is the nationality of the band or the artist.
Our job it to summarize all the nationalities of all the bands, then print them.
For example, for input:
```
Taylor Swift U.S.
the Beattles U.K.
the Dynasty Tang China
the May Flower China
```
The output should be:
```
China
U.K.
```
Now, fill in the blanks below:
```Java
public class Main {
public static void main(String[] args) {
Scanner in = new Scanner(System.in);
ArrayList
while ( in.hasNextLine() ) {
String line = in.nextLine();
lst.add(line.split(" "));
}
Set
.filter(@@[x->x[0].equals("the")](2))
.map(@@[x->x[x.length-1]](2))
.collect(Collectors.@@[toSet()](1));
ArrayList
Collections.sort(r);
for ( String s: r ) {
System.out.println(s);
}
in.close();
}
}
```
答案:
第1空:x->x[0].equals("the")
第2空:x->x[x.length-1]
第3空:toSet()