Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Error in collections

  1. #1
    Junior Member
    Join Date
    Jan 2011
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Error in collections

    Hi all,

    Am trying to create simple Employ name collection i created one set and entered the elements into that with out any error . now am trying to use the contains method but am getting error please check my program and give me the solution please .
    import java.util.*;
    import java.util.Set;
    import java.lang.String;
    class EmpCollPrg
    {
    public static void main(String arg[])
    {
    Set Empset = new HashSet();
    Empset.add("Kiran");
    Empset.add("Shanker");
    Empset.add("Dharma");
    Empset.add("Feroz");
    Empset.add("Hanuman");
    Empset.add("Kamini");
    Empset.add("Srikanth");
    boolean contains(Empset "Kiran")
    System.out.println(Empset);
    Set Sortedset = new TreeSet(Empset);
    System.out.println(Sortedset);

    }
    }


  2. #2
    Member DanBrown's Avatar
    Join Date
    Jan 2011
    Posts
    134
    My Mood
    Confused
    Thanks
    1
    Thanked 12 Times in 12 Posts

    Default Re: Error in collections


    boolean contains(Empset "Kiran")

    what is this.
    Thanks and Regards
    Dan Brown

    Common Java Mistakes

  3. #3
    Junior Member
    Join Date
    Jan 2011
    Posts
    17
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Re: Error in collections

    Actually i tried to use contains method but i don't have correct syntax of that. that y i declared like that
    .

  4. #4
    Super Moderator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,225
    Thanks
    176
    Thanked 817 Times in 760 Posts
    Blog Entries
    5

    Default Re: Error in collections

    Quote Originally Posted by pokuri View Post
    Actually i tried to use contains method but i don't have correct syntax of that. that y i declared like that
    .
    Have a look at the API for Collection. You pass an object to the contains method and it returns a boolean.
    boolean contains = myCollection.contains("This");

Similar Threads

  1. Collections
    By pokuri in forum Collections and Generics
    Replies: 4
    Last Post: June 3rd, 2011, 09:08 AM
  2. [SOLVED] 2D Collections. How to make them and is it a good idea to do so?
    By javapenguin in forum What's Wrong With My Code?
    Replies: 3
    Last Post: January 15th, 2011, 12:38 AM
  3. Help me to Choose Collections
    By kathir0301 in forum Collections and Generics
    Replies: 1
    Last Post: December 3rd, 2010, 09:14 AM
  4. Generics collections and reflection
    By juza in forum Collections and Generics
    Replies: 2
    Last Post: November 30th, 2010, 02:14 AM
  5. how to sort objects with collections???
    By kyros in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 31st, 2010, 02:21 PM