In C# there is a way of reducing the length of an if-statement by using Enumerable.Any to check if elements in a sequence satisfy a condition (http://ift.tt/1GVXgdl).
For example Instead of:
If ( string.Contains(">") || string.Contains("<") || string.Contains("&") || string.Contains("l") || string.Contains("p") )
We can use
if (new [] { ">", "<", "&", "l", "p"}.Any(w => string.Contains(w)))
Is there an equivalent, if not better, way of doing this in Java?
Aucun commentaire:
Enregistrer un commentaire