A basic LinkedList Implementation in java(J2ME compatible)

Java programming topics
Post Reply
User avatar
Herath
Major
Major
Posts: 417
Joined: Thu Aug 05, 2010 7:09 pm

A basic LinkedList Implementation in java(J2ME compatible)

Post by Herath » Tue Aug 24, 2010 6:22 pm

I wanted a LinkedList implementation in J2ME for my on going work on a MSN client. J2ME does not have a built in LinkedList implementation. So I wrote this. Not very advance though. :)

I am sharing this because I could not find a good implementation via google. I hope that this will be of some use to some one. At least to a beginner. :D

Usage Example;
(This implementation support storing String type LinkedList, but you can change it)

Code: Select all


LinkedList linkedList=new LinkedList();

linkedList.insertFirst("How ");
linkedList.insertFirst("Hello,");
linkedList.insertLast("are ");
linkedList.insertLast("you?");

//reading the linked list;

LLNode temp=linkedList.removeFirst();/*reading this way destroys your linked list*/
/*But I want this behaviour of a queue in my app*/

    while(temp!=null){
        System.out.println(temp.data);
        temp=li.removeFirst();
    }
I haven't fully tested this implementation. I did not check removeLast at all. :!:
Suggestions are welcome!
src.zip
LLNode.java and LinkedList.java
(769 Bytes) Downloaded 653 times
Last edited by Herath on Wed Aug 25, 2010 12:30 pm, edited 2 times in total.
User avatar
Neo
Site Admin
Site Admin
Posts: 2642
Joined: Wed Jul 15, 2009 2:07 am
Location: Colombo

Re: A basic LinkedList Implementation in java(J2ME compatible)

Post by Neo » Wed Aug 25, 2010 11:56 am

Good job. Keep up the good work.
Post Reply

Return to “Java Programming”