Checking if long is in array

▼魔方 西西 提交于 2019-12-14 02:14:35

问题


I need to make sure that a certain long value isn't in an array. But for some reason, this isn't working...

!d.toString().contains(sq.toString());

I am sure I am getting something really backwards... but I can't figure out what!


回答1:


Try

!Arrays.asList(d).contains(sq);



回答2:


Look at the static methods in java.util.Arrays. Your array will need to be sorted for the binarySearch() to work.



来源:https://stackoverflow.com/questions/5010044/checking-if-long-is-in-array

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!