• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

LinkedList using Generics

 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Your code works fine for me.what error messages are you getting?can you post it?
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Sheriff
Posts: 22783
131
Eclipse IDE Spring VI Editor Chrome Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 202
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can you use generics only java 5.
 
Campbell Ritchie
Marshal
Posts: 79177
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am not using any userdefined linkedlist class..
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic