is there a Java equivalent to Javascript's “some” method?

前端 未结 4 1489
温柔的废话
温柔的废话 2021-02-19 16:58

I have a collection and I would like to know if at least one element meets some condition. Essentially, what some does in JavaScript, I would like to do on a collection!

4条回答
  •  萌比男神i
    2021-02-19 17:41

    Java doesn't have this feature built-in. Javascript's some() accepts a function pointer as an argument, which is not something that's natively supported in Java. But it should be fairly straight forward to emulate the functionality of some() in Java using a loop and and an interface for the callback functionality.

提交回复
热议问题