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 3 of 3

Thread: How can I convert a String to Set<String>? Is it possible?

  1. #1
    Member
    Join Date
    Aug 2010
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default How can I convert a String to Set<String>? Is it possible?

    I have a method with argument of type Set<String>. The variable which i should use as a paramter of the method is type String. What is the solution ?

    Method:
    public static Data searchAnd(Set<String> keywords) throws IllegalAccessException {
    }
    Variable:
    String searchedValue=request.getParameter("formtext2");
    ...
    //this gives an error
    Searcher.searchAnd(searchedValue);


  2. #2
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: How can I convert a String to Set<String>? Is it possible?

    Add your string to a Set, then pass that object as a parameter:
    Set<String> set = new HashSet<String>();
    set.add(myString);
    Searcher.searchAnd(set);

  3. #3
    Member
    Join Date
    Aug 2010
    Posts
    33
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How can I convert a String to Set<String>? Is it possible?

    It worked just fine!
    Just one remark: Searcher.searchAnd(set) should be inside a try/catch clause.

    Thank you for the help!

Similar Threads

  1. [SOLVED] convert String to int
    By b109 in forum Java Theory & Questions
    Replies: 3
    Last Post: June 3rd, 2010, 03:05 AM
  2. Convert object to String
    By innspiron in forum What's Wrong With My Code?
    Replies: 2
    Last Post: March 15th, 2010, 08:48 AM
  3. Conversion of string into integer in Java
    By JavaPF in forum Java Programming Tutorials
    Replies: 17
    Last Post: January 23rd, 2010, 09:33 AM
  4. Convert string to int?
    By connex in forum Java Theory & Questions
    Replies: 1
    Last Post: December 9th, 2009, 05:06 AM
  5. Convert CHAR to STRING
    By fh84 in forum What's Wrong With My Code?
    Replies: 11
    Last Post: October 29th, 2009, 09:21 PM