1 / 4

Cursors in java collection - quipoin

In Java mainly two types of cursors: Iterator and List Iterator.<br>Both are pre-defined Interfaces present in java.util package.<br>Iterator and List Iterator are used to traverse a group of objects.<br>List Iterator is used to traverse objects either in a forward direction or in a backward direction. i.e. bi-directional cursor.

quipoin
Download Presentation

Cursors in java collection - quipoin

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Cursors in Java collection cursors in Java

  2. Overview • In Java mainly two types of cursors: Iterator and List Iterator. • Both are pre-defined Interfaces present in java.util package. • Iterator and List Iterator are used to traverse a group of objects. • List Iterator is used to traverse objects either in a forward direction or in a backward direction. i.e. bi-directional cursor.

  3. Program import java.util.ArrayList; import java.util.Iterator; public class Test { public static void main(String[] args) { ArrayListaList=new ArrayList<>(); aList.add(10); aList.add("Praveen"); aList.add(15.50); aList.add(21); Iterator i=aList.iterator(); while(i.hasNext()) { System.out.println(i.next()); } System.out.println("-------------------------------"); System.out.println("List before remove:\n"+aList); System.out.println("-------------------------------"); aList.remove(2);//Index 2 value is 12.20 System.out.println("List after remove:\n"+aList); } }

  4. Output: 10 Praveen 15.5 21 ------------------------------- List before remove: [10, Praveen, 15.5, 21] ------------------------------- List after remove: [10, Praveen, 21]

More Related