判断一个数组是否有指定的对象
我有一个由 X 个 2DPoint 组成的数组,我的目标是执行布尔运算来检查该数组是否具有指定的 2DPoint。像这样的事情:
Point2D.Double arrayPoints[] = new Point2D.Double[numberOfPoints];
Point2D.Double pointPVariable = new Point2D.Double(positionXVariable,positionYVariable);
arrayPoints[variableNumber] = pointPVariable;
if(arrayPoints has the Point2D(2.45,6.52)){
do this
}
我怎样才能进行布尔运算?非常感谢!
I have an array composed of an X number of 2DPoints, and my goal is to do a boolean operation that could check if that array has the specified 2DPoint. Something like this:
Point2D.Double arrayPoints[] = new Point2D.Double[numberOfPoints];
Point2D.Double pointPVariable = new Point2D.Double(positionXVariable,positionYVariable);
arrayPoints[variableNumber] = pointPVariable;
if(arrayPoints has the Point2D(2.45,6.52)){
do this
}
How can I do that boolean operation?? Thank you very much!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
只要被比较的类重写 equals 方法,这种方法就有效。
This works as long as the classes being compared override the equals method.
如果您的数组按照
Point2D.Double
的自然顺序排序,则可以使用Arrays.binarySearch
方法。If your array is sorted with the natural ordering of
Point2D.Double
, you can use theArrays.binarySearch
method.