I have set like:
Set<String>
I need on each element of Set make split by ; and create new Set that will contain only 2-nd element. Should I make it directly one by one or exists better way?
Thanks.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
If you can relax your constraint of an output being a
Set<String>to being aCollection<String>you could use Guava and defer the transformation of elements until enumeration of elements through the Collections2#transform() method. You would just have to write a custom function to perform the split on an individual element.But if you cannot/should not relax this constraint, you are best left to doing the already proposed individual iterations (as it’d be much more legible).
Code would look something like: