0% found this document useful (0 votes)
43 views1 page

Java List Implementation Guide

This document contains code examples demonstrating the use of ArrayLists and LinkedLists in Java. The ArrayList code creates a list, adds string elements "A", "B", and "c", then iterates through the list printing the elements. The LinkedList code performs the same functions using a LinkedList instead of an ArrayList. Both examples create an iterator and loop through the list to print out the contents.

Uploaded by

Milan Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
43 views1 page

Java List Implementation Guide

This document contains code examples demonstrating the use of ArrayLists and LinkedLists in Java. The ArrayList code creates a list, adds string elements "A", "B", and "c", then iterates through the list printing the elements. The LinkedList code performs the same functions using a LinkedList instead of an ArrayList. Both examples create an iterator and loop through the list to print out the contents.

Uploaded by

Milan Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

ARRAY LIST

import java.io.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.Scanner.*;
public class Exam {

public static void main(String[] args)


{
ArrayList<String>list=new ArrayList<String>();
list.add("A");
list.add("B");
list.add("c");

Iterator iterator=list.iterator();
System.out.println("List elements");
while(iterator.hasNext())
System.out.println(iterator.next()+" ");
System.out.println();

LINKED LIST

import java.io.*;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner.*;
public class not {

public static void main(String[] args)


{
List<String>list=new LinkedList<String>();
list.add("A");
list.add("B");
list.add("c");

Iterator iterator=list.iterator();
System.out.println("List elements");
while(iterator.hasNext())
System.out.println(iterator.next()+" ");
System.out.println();

You might also like