过滤 csv 按分类重排

csv 文件有 4 列,编号、电影名、类型、导演。

idSale,Movie,Genre,Director

100,Inception,Sci-Fi,Christopher Nolan

101,Man of Steel,Action,Steven Spielberg

102,Interstellar,Sci-Fi,Christopher Nolan

103,The Matrix,Sci-Fi,Steven Spielberg

104,Memento,Thriller,Christopher Nolan

105,Gladiator,Action,Steven Spielberg

106,Dunkirk,War,Christopher Nolan

107,The Godfather,Drama,Steven Spielberg

108,Tenet,Sci-Fi,Christopher Nolan

109,Pulp Fiction,Drama,Steven Spielberg

110,Insomnia,Thriller,Christopher Nolan

111,Fight Club,Drama,Steven Spielberg

112,Following,Thriller,Christopher Nolan

113,The Shawshank Redemption,Drama,Steven Spielberg

114,The Prestige,Drama,Christopher Nolan

115,Forrest Gump,Drama,Steven Spielberg

116,Batman Begins,Action,Christopher Nolan

117,The Lion King,Animation,Steven Spielberg

118,The Dark Knight,Action,Christopher Nolan

119,The Avengers,Action,Steven Spielberg

用 Java 实现:以导演为参数过滤该文件,按类型重新排序,先打印类型,再打印出该类型的电影。比如参数是 Christopher Nolan 时。

Genre: Action

Batman Begins

The Dark Knight

Genre: Drama

The Prestige

Genre: Sci-Fi

Inception

Interstellar

Tenet

Genre: Thriller

Memento

Insomnia

Following

Genre: War

Dunkirk

SPL脚本:


A

B

1

=T("movies.csv").select(Director==arg_director)


2

for A1.group(Genre)

=output("Genre:",A2.Genre)

3


>A2.run(output(Movie))

A1:打开csv,按导演过滤。

A2:按类型分组,每次循环一组。

Java 集成 SPL 可参考 Java 如何调用 SPL 脚本

问题来源:https://stackoverflow.com/questions/76789813/java-search-csvfile-using-arrays