Skip to content


AWT Choice Control Example

AWT Choice Control Explained

Top portion of the Frame window has the AWT Choice Control. There are two Text fields in the Frame. The first one takes a string and adds it to the Choice Control via Add button click. The next text field is used to display the selected text of the Choice Control. Moreover, the Remove button click will use this text field to delete an item in the Choice.

Java Iterator and its hasNext and next methods

Java Iterator Over Collection

The Java Iterator is a reference over a collection object. It can be ArrayList, LinkedList anything which implements the basic Collection Interface. With the iterator we can get all the items in the collection one by one. We can iterate over the collection via a loop or via a for-each construct. But, using these, we cannot adjust the structure while the iteration is in-progress. Whereas with Java Iterator, we can remove items while the iteration is going on.

Java Iterator is a Forward-Only Cursor. This means one can iterate the collection items only in forward direction. Standard Java Iterator does not allow the reverse way of iteration. Also, note the Standard Java Iterator does not allow adding the items even though it allows removal. In this example, we will learn about the Iterator using an ArrayList collection object.

Getting Queue Element From Head For Inspecting

Using Java Queue via LinkedList

The Queue operates on ‘First In First Out (FIFO)’ principle. This means an element added first to the Queue removed first from the queue. For example, in a railway ticket counter the person who enters the queue first will be served first and removed from the queue. Each new person coming to buy the ticket will stand in the tail end of the queue. The same Queue will work in Java. In simple words, elements are added to the tail end of the Queue and removed from the head of the Queue.

In this example, we will see how to use Java Linked as a Queue.