Skip to content

Tag: iterator

Backward Traverse using ListIteartor in java

I am new to java and learning from a very basic level. I am trying to run this below code which is not showing any result in the console. It’s only working when I add forward traverse code before it. Can anyone please help me with that? Thanks Answer When you create a list iterator with a call to myList…

Latency in Iterator or foreach

i have one ArrayList that has a 1000 Insert SQL statement. but rather in execution time the latency of Iterator or (enhanced for loop) for this ArrayList take 1 minute . and my JFrame is not responding in this period. what can i do? Thanks Answer foreach internally uses iterator only, in order to handle bulk …

Iterator vs for

I was asked in an interview what is the advantage of using iterator over for loop or what is the advantage of using for loop over iterator? Can any body please answer this? Answer First of all, there are 2 kinds of for loops, which behave very differently. One uses indices: This kind of loop isn’t alway…

What are fail-safe & fail-fast Iterators in Java

There are two types of iterators in Java: fail-safe and fail-fast. What does this mean, and is the difference between them? Answer What is the difference between them … “Fail-safe” (in engineering) means that something fails in a way that causes no or minimal damage. Strictly speaking, there…

hasPrevious() Method not working

I don’t understand why my hasPrevious iterator is not functioning, it looks like this: I have another function using hasNext() and it works, but this one will not. I am not sure if this method is no longer in existence or not, but when I look into it, Java websites speak of it. I don’t understand …

Find element position in a Java TreeMap

I am working with a TreeMap of Strings TreeMap<String, String>, and using it to implement a Dictionay of words. I then have a collection of files, and would like to create a representation of each file in the vector space (space of words) defined by the dictionary. Each file should have a vector represe…