0% found this document useful (0 votes)
5 views5 pages

Java ArrayList and LinkedList Examples

The document contains several Java classes demonstrating the use of ArrayList and LinkedList from the Java Collections Framework. Each class includes a main method that creates an ArrayList or LinkedList, adds various types of elements, and prints the contents. The examples illustrate the ability to store heterogeneous data in ArrayLists and the basic functionality of LinkedLists.

Uploaded by

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

Java ArrayList and LinkedList Examples

The document contains several Java classes demonstrating the use of ArrayList and LinkedList from the Java Collections Framework. Each class includes a main method that creates an ArrayList or LinkedList, adds various types of elements, and prints the contents. The examples illustrate the ability to store heterogeneous data in ArrayLists and the basic functionality of LinkedLists.

Uploaded by

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

Array_List

1.

package array_list;

import [Link];

public class A {

public static void main(String[] args) {

ArrayList x=new ArrayList();

[Link](10);

[Link]("dev");

[Link](new Integer(30));

[Link](x);

2.

package array_list;

import [Link];

public class B {

public static void main(String[] args) {

ArrayList x=new ArrayList();

[Link](10);

[Link](20);
[Link]("Dev");

[Link](new Integer(30));

[Link](true);

[Link](10.3);

[Link](x);

3.

package array_list;

import [Link];

public class C {

public static void main(String[] args) {

ArrayList<String> str= new ArrayList<String>();

//displaying the initial size

[Link]("Size at the beginning "+[Link]());

//add elements

[Link]("Hello");

[Link]("Hi");

[Link]("Namaste");
[Link]("Bonjour");

//displaying the ArrayList

[Link](str);

4.

package array_list;

// In ArrayList we can store hetrogeneous data

import [Link];

public class E {

public static void main(String[] args) {

ArrayList x=new ArrayList();

[Link](10);

[Link](20);

[Link]("Dev");

[Link](true);

[Link](10.3);

[Link](x);

}
5.

package array_list;

import [Link];

public class F {

public static void main(String[] args) {

ArrayList x=new ArrayList();

[Link](10);

[Link](20);

[Link]("Dev");

[Link](x);

LinkedList
1.

package array_list;

import [Link];
public class D {

public static void main(String[] args) {

LinkedList<Integer> x=new LinkedList<Integer>();

[Link](100);

[Link](200);

[Link](x);

You might also like