我有一个代码片段,它是
List<String> mylist = new ArrayList<String>();
mylist.add("ren");
mylist.add("rahul->RC");
mylist.add("arun");
String sr = "rahul->RC";
String sr1 = "rahul";
for ( int i=0;i<mylist.size();i++ )
{
if(mylist.get(i).contains(sr))
{
System.out.println(mylist.get(i)+" CONTAINS "+sr);
mylist.remove(mylist.get(i));
System.out.println("Inside : "+mylist);
mylist.add("again");
break;
}
if(mylist.get(i).equals(sr1));
{
System.out.println(sr1 +" EQUELS " +mylist.get(i));
mylist.remove(mylist.get(i));
mylist.add(sr);
break;
}
}
System.out.println("Final Output => "+mylist);
当我运行这段代码时,我得到的输出为
rahul EQUELS ren
Final Output => [rahul->RC, arun, rahul->RC]
我想知道我什么时候看到这个输出。这怎么会rahul EQUELS ren
发生?我想不通问题所在?请帮我解决这个问题。