1.Basic Java example program to iterate arraylist elements using list iterator
Output:
- package com.javaIteratelist;
- import java.util.ArrayList;
- import java.util.Collections;
- import java.util.Iterator;
- public class IterateList{
- public static void main(String[] args) {
- //create an ArrayList object
- List<String> instanceofjavaList = new ArrayList<String>();
- //Add elements to Arraylist
- // add 5 different values to arraylist
- instanceofjavaList.add("Interview Questions");
- instanceofjavaList.add("Interview Programs");
- instanceofjavaList.add("Concept and example program");
- instanceofjavaList.add("Concept and interview questions");
- instanceofjavaList.add("Java Quiz");
- for (int i = 0; i < instanceofjavaList.size(); i++) {
- System.out.println(instanceofjavaList.get(i));
- }
- }
- }
Output:
- Interview Questions
- Interview Programs
- Concept and example program
- Concept and interview questions
- Java Quiz