I have an array list declared like this:
val aName = new ArrayList
I add names in this array via the add().
When I print them, I only want to print specific names (e.g. all with names "Charlie" and working at the department Finance).
In my for loop, I have this:
for (m: aName.filter[!CDirectoryFacade::instance.isNameUsed(toString)])
{
print(m)
}
The loop above did not print the name at all. Because my function isNameUsed() did not receive the string as I expect, but rather it receives the address as a String
org.generator.myDsl.myDslGenerator@67bd0a26
However, I do not seem to have problem when I do not use filter().
for (m: aName)
{
if (!CDirectoryFacade::instance.isNameUsed(m))
{
print(m)
}
}
Can anyone suggest on how to use the filter() with Strings?
It's hard to tell because your code snippet doesn't provide any types and it is not clear where
name
comes from in theprint
expression. But the code above should probably read like this:I could be even more concise: