- import java.util.ArrayList;
- import java.util.Iterator;
- public class IterateThroughArrayListUsingIteratorExample {
- public static void main(String[] args) {
- //create an ArrayList object
- ArrayList arrayList = new ArrayList();
- //Add elements to Arraylist
- arrayList.add("1");
- arrayList.add("2");
- arrayList.add("3");
- arrayList.add("4");
- arrayList.add("5");
- //get an Iterator object for ArrayList using iterator() method.
- Iterator itr = arrayList.iterator();
- System.out.println("Iterating through ArrayList elements...");
- while(itr.hasNext()){
- System.out.println(itr.next());
- }
- }
- }
Search This Blog
Labels
- Apache Http Client (4)
- Array (3)
- Array List (12)
- Assertion (2)
- Calendar (20)
- Collection (7)
- Common Sol (14)
- Core Java (36)
- Date (4)
- Design Pattern (2)
- Display Tag (4)
- Eclipse (3)
- Enum (2)
- Exception Handling (5)
- How To (6)
- HttpURLConnection (2)
- ImageIO (2)
- Inner Class (1)
- Java Interview Q (1)
- Java IO (6)
- Java Mail (4)
- JDBC (1)
- JSON (5)
- JSP (2)
- JSTL (2)
- MYSQL (1)
- Platform Environment (3)
- Reg Ex (1)
- Serialization (1)
- Servers (3)
- Servlet JSP (3)
- Singleton Pattern (2)
- SQL (2)
- String Handling (11)
- Struts (5)
- Synchronization (5)
- Threads (6)
- Web Services (3)
0 comments:
Post a Comment