You need to sign in to do that
Don't have an account?
rohitr
Set to String
Hi Guys,
I've a set with single element.
I need to get the value in the set to a string.
public Set<String> closeMonthDateSet;
The closeMonthDateSet set will have a single value which i need to put into a string.
Can anyone help me on this?
If you are sure that always that set contains 1 single String value...
then you can do like below
String myString;
if(closeMonthDateSet != NULL && closeMonthDateSet.size()>0){
myString = closeMonthDateSet.get(0);
}
Now the myString contains the 1st String value present in that Set
All Answers
Set<String> closeMonthDateSet = new Set<String>{'abc'};
String closeMonthDate;
for (String s: closeMonthDateSet) {
closeMonthDate = s;
}
If you are sure that always that set contains 1 single String value...
then you can do like below
String myString;
if(closeMonthDateSet != NULL && closeMonthDateSet.size()>0){
myString = closeMonthDateSet.get(0);
}
Now the myString contains the 1st String value present in that Set
Another alternative might look like this code. While not necessarily the shortest code to read, it counts as only one line of execution.