简体   繁体   中英

java Stream() showing error while using .replaceAll() method on list of String

I have a database of movies which contains things like, title, year, list of actors, list of producers and list of directors. I am trying to develop a method that takes the actor's real name and replaces it with actor's stage name as stored in the database. I came up with following code.

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
    }

You could use a simple forEach with List#replaceAll to update your existing collection such as:

data.forEach(movie -> movie.getActors().replaceAll(m -> m.replace(realName, stageName)));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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