我有一个数组,如果它在数组中,我想检查最后的数字。
例子:
String[] types = {".png",".jpg",".gif"}
String image = "beauty.jpg";
// Note that this is wrong. The parameter required is a string not an array.
Boolean true = image.endswith(types);
请注意: 我知道我可以使用 for 循环检查每个单独的项目。
我想知道是否有更有效的方法来做到这一点。原因是图像字符串已经在不断变化的循环中。
最佳答案
Arrays.asList(types).contains(image.substring(image.lastIndexOf('.') + 1))
关于java - 在 Java 上使用 String.endswith() 方法,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11106696/