Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

java list iterator example

// Java program to Iterate the Elements
// in an ArrayList

// Importing java utility classes
import java.util.*;

// Main class
public class Main {

	// main driver method
	public static void main(String args[])
	{
		// Creating an empty Arraylist of string type
		List<String> list = new ArrayList<>();

		// Adding elements to above object of ArrayList
		list.add("Mango");
		list.add("Banana");

		// Adding element at specified position
		// inside list object
		list.add(1, "Apple");

		// Using for loop for iteration
		for (int i = 0; i < list.size(); i++) {

			// Using get() method to
			// access particular element
			System.out.print(list.get(i) + " ");
		}

		// New line for better readability
		System.out.println();

		// Using for-each loop for iteration
		for (String str : list)

			// Printing all the elements
			// which was inside object
			System.out.print(str + " ");
	}
}
Comment

PREVIOUS NEXT
Code Example
Java :: get runtime java 
Java :: java do while loop 
Java :: java number reverse 
Java :: java wrapper classes 
Java :: what is a package in java 
Java :: Valid regex check java 
Java :: java continue statement 
Java :: java packages example 
Java :: selenium java control + enter 
Java :: Java telegram bot dependency 
Java :: procedure java 
Java :: java int 0/0 
Java :: the import junit cannot be resolved maven 
Java :: MD5 java 
Java :: java final variable 
Java :: for() in java 
Java :: spring boot send api request 
Java :: string length java 
Java :: generate hash in java 
Java :: java hex to rgb 
Java :: is it possible to declare two conditions in for loop in javascrip 
Java :: c++ vs java 
Java :: java application 
Java :: inorder traversal 
Java :: how to use a while statement with char in java 
Java :: calculate the area of two squares in java by using a method 
Java :: two dimensional arraylist in java 
Java :: session management in java spring boot for login logut 
Java :: coin flip random java 
Java :: gson to class 
ADD CONTENT
Topic
Content
Source link
Name
7+4 =