endswith java_Java Path endsWith()用法及代码示例

EndsWith(其他路径)java.nio.file.Path的方法,用于检查此路径是否以给定路径作为方法的参数结束。如果此路径以给定路径结束,则此方法返回true;否则,返回true。否则为假。

如果传递的路径具有N个元素,并且没有根成分,并且此路径具有N个或更多元素,则如果每个路径的最后N个元素(从距离根最远的元素开始)相等,则此路径以给定路径结尾。

如果传递的路径具有根成分,则此路径以给定路径结束,如果该路径的根成分以给定路径的根成分结束,并且两个路径的相应元素相等。此路径的根部分是否以给定路径的根部分结尾是filesystem-specific。如果此路径没有根组件,并且给定路径具有根组件,则该路径不会以给定路径结尾。

如果给定的路径与与此路径不同的FileSystem关联,则返回false。

用法:

boolean endsWith(Path other)

参数:此方法接受单个参数other,它是给定的路径。

返回值:如果此路径以给定路径结尾,则此方法返回true;否则,此方法返回true。否则为假。

以下示例程序旨在说明endsWith(Path other)方法:

示例1:

// Java program to demonstrate

// java.nio.file.Path.(Path other) method

import java.nio.file.Path;

import java.nio.file.Paths;

public class GFG {

public static void main(String[] args)

{

// create an object of Path

Path path

= Paths.get("D:\\eclipse"

+ "\\plugins"

+ "\\javax.xml.rpc_1.1.0.v201209140446"

+ "\\lib");

// create a path object which we will pass

// to endsWith method to check functionality

// of endsWith(Path other) method

Path passedPath = Paths.get(

"javax.xml.rpc_1.1.0.v201209140446"

+ "\\lib");

// call endsWith() to check path object

// ends with passedPath or not

boolean check = path.endsWith(passedPath);

// print result

System.out.println("Path ends with "

+ passedPath + " :"

+ check);

}

}

输出:

bdd4eded08a51e06daff53fef2e24bf9.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值