Cracking the #Java #Coding #Interview - Question 152: How can you loop backward? Watch all the questions here: • Cracking the Java Codi...
Пікірлер: 24
@siriusmain1763Ай бұрын
Youngest Java enthusiast
@loic.bertrandАй бұрын
In Java 21 you can also use the reversed() method on SequencedCollection and SequencedMap which returns a reversed view of the collection.
@_PranayWАй бұрын
Tell me how can I learn Java? Any websites or video?
@heeteshdoorbizАй бұрын
@_PranayW Choose a FreeCodeCamp video. Write code along the way when watching video. You don't need to understand everything it will slowly make sense later as you keep coding.
@SpeigerАй бұрын
Technically all set/Maps can be iterated backwards too because they have a forwards iterating order that is consistent meaning you can easily implement a backwards implementation.
@shashankmutgi933024 күн бұрын
Is that Jose Paumard? This guy's course on completablefuture landed me my current job. Thanks Jose!
@csm2526Ай бұрын
Why predefined methodscwhile you can rotate using for loop starting from nth element by reducing 1 each until the index>=0. Also using do while starting ftom nth element by reducing 1 each until the index>=0
@sergios6794Ай бұрын
That traditional forloop is not recommended if you only have the object through the interface List (you don't know the implementation), because depending on the implementation, the get(int index) method can have a really bad performance for executing in a loop, like a LinkedList.
@csm2526Ай бұрын
@@sergios6794 why get method Sir just call the toArray. Mylist[]=list.toArray(); now for(int i=Mylist.length;i>=0;i--)s.o.p(Mylist[i]); simply reverse the list.
@csm2526Ай бұрын
@@sergios6794I hope yiu are convinced now
@jay_senszАй бұрын
@@sergios6794 That may be technically true, but in practice LinkedList is essentially obsolete because ArrayList is more performant (and less memory intense) under most circumstances.
@sergios6794Ай бұрын
@@jay_sensz I did an example, linkedlists and arraylists are not the only implementations of list. External libraries can provide their own implementation, that's because i said "when you only have the interface object"
@abhishekghosh2293Ай бұрын
If we have an ArrayDeque that has some elements, then we can use - descending iterator. something like this. It's super useful. Deque stack = new ArrayDeque(); Iterator itr = stack.descendingItrerator(); while(itr.hasNext()) { // Do some processing someList.add(itr.next()); }
@hamza201183Ай бұрын
Or a for-loop with i-- :p
@JuanGarcia-zy8ywАй бұрын
No sir … forget about that imperative style
@hamza201183Ай бұрын
@@JuanGarcia-zy8yw It just answers the question too. But aren't the suggested answers in the video also imperative?