Java program to demonstrate different methods to iterate through a list