Reputation: 103
I have this ArrayList
ArrayList<TvShowEpisode> mEpisodes = new ArrayList<TvShowEpisode>();
in this example let's say mEpisodes
returns 3 elements
mEpisodes = [
{
mEpisode = "10",
mTitle = "orange",
mSeason = "05",}
{
mEpisode = "11",
mTitle = "black",
mSeason = "05",}
{
mEpisode = "12",
mTitle = "blue",
mSeason = "05",}
]
what I want is to make an ArrayList out of mEpisodes
that returns the value of mEpisode
meaning {10, 11, 12}
Upvotes: 0
Views: 139
Reputation: 215
Use stream:
mEpisodes.stream().map(episode -> episode.mEpisode).collect(Collectors.toCollection(ArrayList::new));
Upvotes: 0
Reputation: 725
If you just want to print/access value of mEpisode then you can do this :
for(TvShowEpisode tvShowEpisode : mEpisodes)
{
System.out.println(tvShowEpisode.mEpisode);
}
If you want to get one value and store it into separate ArrayList which should be String type than do this:
ArrayList<String> mEpidsodeNames = new ArrayList<>();
for(TvShowEpisode tvShowEpisode : mEpisodes)
{
mEpidsodeNames.add(tvShowEpisode.mEpisode);
}
Upvotes: 1