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:
Code :
public static Data searchAnd(Set<String> keywords) throws IllegalAccessException {
}
Variable:
Code :
String searchedValue=request.getParameter("formtext2");
...
//this gives an error
Searcher.searchAnd(searchedValue);
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:
Code java:
Set<String> set = new HashSet<String>();
set.add(myString);
Searcher.searchAnd(set);
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!