-3
package treeset;

import java.util.*;
public class TreeSet {
public static void main(String[] args) {       
SortedSet<String> herbSetOrder = new TreeSet<String>(herbSet); 
System.out.println("First herb is: " + herbSetOrder.first()); 
System.out.println("Last herb is: " + herbSetOrder.last()); 
    }   
}

I want to print the first and last element in the Set but it give me an error say "TreeSet does not take parameters"?

  • Please show the exact error you have, since `TreeSet` has a constructor that accepts a `Collection`. – amit May 05 '14 at 05:36
  • What you want is to create a `new java.util.TreeSet(herbSet)`. – Edwin Dalorzo May 05 '14 at 05:40
  • 'SortedSet herbSetOrder = new TreeSet(herbSet);' – user3579276 May 05 '14 at 05:43
  • Not usually a good idea to give your class the same name as the API class that you're using inside it. Your problem here is that the compiler thinks you want your _own_ class, at `new TreeSet`, and is complaining that _your_ class is not a generic, unlike `java.util.TreeSet`. – Dawood ibn Kareem May 05 '14 at 05:43

1 Answers1

3

You have your own TreeSet class, so it is used instead of java.util.TreeSet. Rename your class and it'd be fine.

TulaGingerbread
  • 435
  • 5
  • 15
  • I rename it stil there is part of error say "it can't find symbol : varible herbSet" – user3579276 May 05 '14 at 05:56
  • That's because you never defined `herbSet` anywhere in your code, or if you did, you didn't post that part. The compiler means exactly what it says. – awksp May 05 '14 at 06:07