gpt4 book ai didi

java - 字符串比较

转载 作者:塔克拉玛干 更新时间:2023-11-01 22:15:45 24 4
gpt4 key购买 nike

<分区>

Possible Duplicate:
How do I compare strings in Java?

我是否以错误的方式比较字符串?请告诉我如何正确比较?谢谢。

private void deleteButtonActionPerformed(java.awt.event.ActionEvent evt) {                                             
String selectedVal = (String) jList1.getSelectedValue();
AbstractListModel model = (AbstractListModel) jList1.getModel();
int numberElements = model.getSize();
final String[] allElements = new String[numberElements + 1];
for (int i = 0; i < numberElements - 1; i++) {
String val = (String) model.getElementAt(i);
***if (selectedVal != val)*** {
allElements[i] = (String) model.getElementAt(i);
}
}
controller.deleteButtonClicked(selectedVal);

jList1.setModel(new javax.swing.AbstractListModel() {

String[] strings = allElements;

public int getSize() {
return strings.length;
}

public Object getElementAt(int i) {
return strings[i];
}
});

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