What is the best way to do the below in Java 8.
I have a list of ColumnInfo objects,
ColumnInfo CLASS has below members
String name
Class<?> type
Object value
I want to iterate list of ColumnInfo objects and if any of them is of type String.class I want to suffix "IS A STRING" to the column name , for other columns I want to return column name as is, the return value should be a comma separated string. The comma separated string should maintain the order of items as is in the incoming List of ColumnInfo objects.
So, if I have column info objects as below
{order_code , Integer.class, 10}
{order_city, String.class ,"france"}
{is_valid, Boolean.class, true}
expected output
order_code, order_city IS A STRING, is_valid
Below is my approach, Is there a better way to do this?
String commaSepStr = columnInfos.stream()
.map(f -> {
String retValue = isString(f)? f.getName()+ " IS A STRING" : f.getName();
return retValue;
}).collect(Collectors.joining(" ,")));