Make array container classes behave like ArrayList
How to make a class that contains a variable that stores an array able to return the inner element holder like
elementData
in ArrayList. For example when we want to iterate in enhanced for loop (var e : elements)
where elements
is an ArrayList , it somehow converts the elements to array to be iterated.
I couldn't find documentations online or find discussions about it. Using toArray doesn't seem to work10 Replies
⌛
This post has been reserved for your question.
Hey @circle! Please useTIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here./close
or theClose Post
button above when your problem is solved. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.
ArrayList
doesn't return an array when iterating over it with a for each loop
what exactly are you talking about?Hmm. When extending a class with
ArrayList
, using this
method would retrieve the #elementData
of itself (or a variable)
it's pretty interestingcan you show an example of what you mean?
toArray
gives you a copy if the data as an arrayThis would compile. Sorry for the boobs
kind of means, that
this
actually retrieves the ArrayList#elementData
right?no
the foreach loop is equivalent to
which is the case for all foreach loops that don't operate on arrays directly
I understand the case with for loop now, it uses an iterator. Thanks
If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.
Post Closed
This post has been closed by <@389034898666553344>.