Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

LinkedList using Generics

 
Karthikeyan Ravindran
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your code works fine for me.what error messages are you getting?can you post it?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
catch(Exception e){}

That's generally not such a good idea. You should at least print out a message that an exception occurred.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50258
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20669
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
camilo lopes
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
can you use generics only java 5.
 
Campbell Ritchie
Sheriff
Pie
Posts: 50258
79
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not using any userdefined linkedlist class..
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic