S
S
Sasha2942020-11-29 23:48:21
Java
Sasha294, 2020-11-29 23:48:21

What are the three ways you can get objects from a collection?

I'm wondering what are the three ways you can get an object from a collection? I don't think I'm new, but I don't know.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
roswell, 2020-11-29
@Sasha294

forEach(), iterator(), stream/parallelStream()

M
mayton2019, 2020-11-30
@mayton2019

In the basic configuration, the Collection interface allows you to retrieve objects through iterator (). A little later in new jdk versions - there is a sequential stream () that calls iterator. And a parallel stream, which is not always supported for all collection implementations. For example, the STDIN class file is only sequential and wrapping it with parallelism is fundamentally impossible.
All other magic methods are just thunks or adapters over an iterator.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question