[英]java Stream() showing error while using .replaceAll() method on list of String
我有一個電影數據庫,其中包含標題、年份、演員名單、制片人名單和導演名單。 我正在嘗試開發一種方法,該方法采用演員的真實姓名並將其替換為存儲在數據庫中的演員藝名。 我想出了以下代碼。
void actorNameChange()
{
Scanner s = new Scanner(System.in);
System.out.println("Actor Real name : ");
String realName = s.nextLine();
System.out.println("Actor stage Name : ");
String stageName = s.nextLine();
List<Movie> movies = data.stream().filter(m -> m.getActors().contains(stageName)).collect(toList());
movies.stream().map(movie -> movie.getActors().stream().sorted(st -> st.replaceAll(realName,stageName)).toArray();
//i am gaetting error here at st.replaceAll() -> method doesn't found
}
您可以使用簡單的forEach
和List#replaceAll
來更新現有的集合,例如:
data.forEach(movie -> movie.getActors().replaceAll(m -> m.replace(realName, stageName)));
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.