Java 用Linkedhashmap值替换ArrayList项

Java 用Linkedhashmap值替换ArrayList项,java,arraylist,linkedhashmap,Java,Arraylist,Linkedhashmap,我有一个名为numericValueMap的Linkedhashmap,它有参数String,String: {a=1,b=1,c=2,d=3,e=5} 我有一个叫做等式的数组列表: { e, -, a, +, b, -, c, *, d, +, b} 我要做的是用Linkedhashmap中的正确值替换Arraylist中的项。以下是我目前的附件: for (final String key: numericValueMap.keySet()) { for (int i = 0, n =

我有一个名为numericValueMap的Linkedhashmap,它有参数String,String

{a=1,b=1,c=2,d=3,e=5}
我有一个叫做等式的数组列表:

{ e, -, a, +, b, -, c, *, d, +, b}
我要做的是用Linkedhashmap中的正确值替换Arraylist中的项。以下是我目前的附件:

for (final String key: numericValueMap.keySet()) {
for (int i = 0, n = equation.size(); i < n; i++) {
String algebraItems = (String) equation.get(i);

if(algebraItems.contains(key)) {
    String newNum = algebraItems.replace(algebraItems, ?);
    equation.set(i,newNum);

  }
 }
 }
for(最终字符串键:numericValueMap.keySet()){
对于(int i=0,n=equation.size();i

代码一直工作到并包括将Arraylist与相应Linkedhashmap键进行比较的点。但是,根据我目前的知识,我无法用正确的值替换Arraylist项。关于我必须使用什么代码有什么想法吗?

如果我理解正确的话-

int index =0;
if((index = arrayList.get(element))>=0)
    arrayList.set(index,replaceElement);

通过迭代LinkedHashMap并访问每个项的键和值来工作,如下所示:

for (Iterator<Entry<String, String>> it = numericValueMap.entrySet().iterator(); it.hasNext();) {
            Entry<String, String> e = it.next();
            String key = e.getKey();
            String value = e.getValue();
for(迭代器it=numericValueMap.entrySet().Iterator();it.hasNext();){
条目e=it.next();
String key=e.getKey();
字符串值=e.getValue();

您可以使用get/set在数组列表的一个循环中执行此操作。使用标准for循环,而不是增强的for循环。使其工作正常谢谢。只需使用迭代器和get方法。将尝试使其与set一起工作,而不是替换。使其与@Perception建议的一起工作。现在尝试退出,看看它是否符合我的需要d、 谢谢你