2

I want to form a new string from ArrayList of Strings with a particular delimiter using spel.

list = ["a", "b", "c"]

I want to make a String s = "a,b,c" from above list.

I tried many expressions such as StringUtils.join(list, ','), list.stream().collect(Collectors.joining(',')), etc. but every time I'm getting an error

EL1008E: Property or field 'StringUtils' cannot be found on object of type 'java.util.LinkedHashMap' - maybe not public or not valid?

Is there any way to do this in spel?

0

3 Answers 3

0

If StringUtils.join is a static method, you need T(com.my.StringUtils).join(...) (need full class name too).

Sign up to request clarification or add additional context in comments.

Comments

0

I think I found an answer, or at least, worked for me in spinnaker's SpEL:

${ T(String).join(',', "a", "b" ,"c" )  }
"a,b,c"

and even better, for my particular use case, to get rid of nasty nulls:

${ T(String).join(',', ({"a", null ,"c"}.?[#this != null]) ) }
"a,c"

and it even worked for:

${ T(String).join(' / ', someList )}
${ T(String).join(' / ', someSimpleMap.values() )}

(by "simple map", I mean, single depth, set of A: B, no nested or otherwise complex maps. Left that adventure to the reader :)

Comments

-2

You can use this instead

String lst[] = new String[]{"a","b","c"};
System.out.println(String.join(",",lst)); //here output will be a,b,c

1 Comment

Sorry but OP was asking for a solution in SpEL (Spring Expression Language), not in plain Java

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.