Page 1 of 1

A basic LinkedList Implementation in java(J2ME compatible)

Posted: Tue Aug 24, 2010 6:22 pm
by Herath
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 740 times

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

Posted: Wed Aug 25, 2010 11:56 am
by Neo
Good job. Keep up the good work.