0

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}

2 Answers 2

1

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);
}
Sign up to request clarification or add additional context in comments.

Comments

0

Use stream:

mEpisodes.stream().map(episode -> episode.mEpisode).collect(Collectors.toCollection(ArrayList::new));

1 Comment

Thanks , but problem is I'm running java 1.7

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.