gpt4 book ai didi

java - 比较字符串和对象属性

转载 作者:行者123 更新时间:2023-12-02 10:09:49 24 4
gpt4 key购买 nike

我尝试使用 .equals() 将字符串与对象属性进行比较,但即使条件为真,条件仍然失败。我尝试使用trim()来去掉尾随空格,但仍然失败。

这是我的代码:

if (status) {
inventoryList = allInventory.getInventory();
assert assetId != null;
for (Inventory inventory : inventoryList) {
if (assetId.trim().equals(inventory.getProductCode().trim())) {

//get the current quantity that exists

new_quantity.setValue(0);

new_quantity.setMaxValue(inventory.getQuantity());
inventoryId = inventory.getId();
return;

} else {
// new_quantity.setVisibility(View.GONE);
decrement.setEnabled(false);
AlertDialog.Builder alert = new AlertDialog.Builder(this);
alert.setTitle("Product not found ");
// prevent cancel of AlertDialog on click of back button and outside touch
alert.setCancelable(false);
alert.setMessage("Product is not in inventory. Do you want to continue scanning?");

alert.setNegativeButton("No", (dialog, which) -> {
onBackPressed();
dialog.dismiss();
}
);
alert.setPositiveButton("Yes", (dialog, which) -> {
Intent scanAsset = new Intent(this, ScanActivity.class);
scanAsset.putExtra("building", building);
scanAsset.putExtra("room", room);
scanAsset.putExtra("department", depart);
scanAsset.putExtra("TAG", "E");
startActivity(scanAsset);
dialog.dismiss();
});
AlertDialog dialog = alert.create();
dialog.show();
}

}

最佳答案

我想向 oracle 文档指出:

Compares this string to the specified object. The result is true if and only if the argument is not null and is a String object that represents the same sequence of characters as this object.

enter image description here

关于java - 比较字符串和对象属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55079434/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com