my dog learned polymorphism*
The moose likes Beginning Java and the fly likes LinkedList using Generics Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "LinkedList using Generics" Watch "LinkedList using Generics" New topic
Author

LinkedList using Generics

Karthikeyan Ravindran
Ranch Hand

Joined: Nov 20, 2007
Posts: 32
I am getteing an error as LinkedList does not take parameters

LinkedList <Integer>queue = new LinkedList<Integer>();
///////////////////////////////////////below is the code

import java.util.*;

public class ListQueueDemo {
public static void main(String args[]) {
int numbers[]={34, 22,10,60,30};
List <Integer>list = new ArrayList<Integer>();
try{
for(int i=0; i<5; i++){
list.add(numbers[i]);
}
System.out.println("the List is: ");
System.out.println(list);
LinkedList <Integer>queue = new LinkedList<Integer>();
for(int i=0; i<5; i++){
queue.addFirst(numbers[i]);
}
System.out.println("The Oueue is: ");
System.out.println(queue);
queue.removeLast();
System.out.println("After removing last element the queue is: "+ queue);

}
catch(Exception e){}
}
}


Hope i get my answer fast


thank u
Laxman Guru
Greenhorn

Joined: Feb 26, 2008
Posts: 17
Your code works fine for me.what error messages are you getting?can you post it?


Laxman
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41068
    
  43
catch(Exception e){}

That's generally not such a good idea. You should at least print out a message that an exception occurred.


Ping & DNS - my free Android networking tools app
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37936
    
  22
Are you using Java 5 or Java 6? Generics was only introduced for Java 5. You might be using an older version.
Karthikeyan Ravindran
Ranch Hand

Joined: Nov 20, 2007
Posts: 32
I am using java5 when i am using it with set its taking but with linkedlist its not taking.. i am getting error as

type linkedlist does not take parameters
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19651
    
  18

Sounds more like you're using Java 1.4 compatibility. I've only seen this error when copying code from a Java 5 project to a Java 1.4 project in Eclipse.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
camilo lopes
Ranch Hand

Joined: Aug 08, 2007
Posts: 202
can you use generics only java 5.


Brazil - Sun Certified Java Programmer - SCJP 5
http://www.camilolopes.com/ About Java - Update every Week.
Guide SCJP - tips that you need know http://blog.camilolopes.com.br/livrosrevistaspalestras/
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 37936
    
  22
Originally posted by camilo lopes:
can you use generics only java 5.
Only Java 5 or more recent (Java 6).
I am using java5 when i am using it with set its taking but with linkedlist its not taking.. i am getting error as

type linkedlist does not take parameters

Is there any chance you have a LinkedList class you have written yourself?
Karthikeyan Ravindran
Ranch Hand

Joined: Nov 20, 2007
Posts: 32
I am not using any userdefined linkedlist class..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: LinkedList using Generics
 
Similar Threads
Adding null values into a LinkedList
LinkedList problem
PriorityQueue - ClassCastException in offer()
get fooled with this programs
How often we will be fooled?