Exercices_java_collection
Exercices_java_collection
ArrayList;
import java.util.Iterator;
// Step 3: Use Iterator to replace each name with its uppercase version
// Step 3: Use Iterator to replace each name with its uppercase version
Iterator<String> iterator = students.iterator();
int index = 0; // To keep track of indices while iterating
while (iterator.hasNext()) {
String name = iterator.next(); // Get the current name
students.set(index, name.toUpperCase()); // Replace with uppercase
index++;
}
System.out.println("list of students in upper case: " + students);
22
// Step 4: Retrieve and print the second student
String secondStudent = students.get(1); // Index starts at 0
System.out.println("The second student is: " + secondStudent);
23
// Step 8: Print the size of the list
System.out.println("The number of students in the list: " + students.size());
24
import java.util.HashMap;
public class HashMapDemo {
public static void main(String[] args) {
27