首先,英语不是我的母语。如有任何错误,请提前致歉!
对于我的一个项目,我想要一个包含用户决定输入的数字的列表,并且所有这些数字都附有一个欧元符号。
现在我的问题是我稍后还需要这些数字来创建方程,显然没有欧元符号。那么,有没有办法将这些数字变成双倍,同时删除 € 呢?
如果没有的话,我会暂时放弃添加欧元符号的想法,但如果能将其添加到我的列表中就好了。
我也尝试在网上搜索,但也许我找不到任何东西,因为我的措辞很奇怪。希望我说的所有这些都是可以理解的。
提前谢谢您!
也许可以使用 JList 的 DefaultListModel 和 ListSelectionModel:
// Get the JList DefaultListModel:
DefaultListModel dlm = (DefaultListModel) jList1.getModel();
// Get the JList ListSelectionModel:
ListSelectionModel selmodel = theList.getSelectionModel();
//Get the Index value of the item selected:
int index = selmodel.getMinSelectionIndex();
// Get the selected String Element from JList:
String stringValue = dlm.getElementAt(index).toString();
// Does the element contain a Euro Symbol?
if (stringValue.contains("\u20AC") {
/* Yes...then remove it from the element string and
trim off any leading/trailing whitespaces: */
stringValue = stringValue.replace("\u20AC", "").trim();
}
// Convert the element value to double type:
double value = Double.parseDouble(stringValue);