plz help me in writing the logic with out using the util packege classes in java? plz give the code for this program in linkedlists way (not by using util package classees)

import java.util.*;
public class arr1
{
public static void main(string args[])
{
list l1=new ArrayList(); // or list l1=new linkedlist();
l1.add("1");
l1.add("2");
l1.add("3");
Iterate i1=l1.iterate();
while(i1.hasNext())
{
 
system.out.println(i1.next());
 
}
}

A linked list is nothing by collection of nodes which contain data and a pointer to the next node.

Node
-----^------
[data | ref] -> [data | ref] -> ....

Create a class called as Node which would have an Object reference to hold reference to objects and a Node reference to hold a pointer to the next node in the linked list.

The linked list class would contain a member variable 'head' of type Node which would point to the head of the list.

As for the rest, you should read up on something related to Linked Lists. Read this and this.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.