java - 如果 Key 是文件对象,Java 如何比较它?

标签 java algorithm api

假设我有一个 HashMap,它存储实际的文件对象作为键,值是它的最后修改日期。

HashMap<File, Long> hashMap = new HashMap<File, Long>();

如果文件(test.log)存在于我的HashMap中(我已经添加了它),但是文件(test.log)后来被修改或更改;当我发出替换时,它会找到现有的匹配对象,还是会更改文件的状态,从而改变对象的性质。因此,我将间接添加一个新的键值对。

hashMap.replace(file, newModifiedTime); 

最佳答案

来自javadoc equal's description

Tests this abstract pathname for equality with the given object. Returns true if and only if the argument is not null and is an abstract pathname that denotes the same file or directory as this abstract pathname. Whether or not two abstract pathnames are equal depends upon the underlying system.

关于java - 如果 Key 是文件对象,Java 如何比较它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14749092/

相关文章:

algorithm - 联合查找算法

c# - 返回表面上所有矩形的高效算法

algorithm - 在具有变化值的两个数组之间进行插值

ios - 使用多个基本 URL 和多个对象管理器 (RestKit)

java - @RequestMapping( method = RequestMethod.POST) 提交后获得 HTTP 状态 405 - 请求方法 'POST'

java - 传递 java 数组并在 spring View 中使用它

php - Laravel POST 请求重定向 302

python - 来自 get_buy_price() 的 API Coinbase ValueError

java - 显示和插入方法错误(双端队列)

java - servlet 和 apache HttpClient 的 UTF-8 编码问题