可以。用事实说话,已测试。如下。涉及到的数据类型 String、int、double、boolean
import java.util.ArrayList;import java.util.List;
public class Test {
@SuppressWarnings("unchecked")
public static void main(String[] args) {
List l = new ArrayList();
l.add(0, "\"");
l.add(1, 1);
l.add(2," + ");
l.add(3,2.0);
l.add(4," == ");
l.add(5,3);
l.add(6, "\"");
l.add(7," is ");
l.add(8,true);
System.out.print("Though 1 + 2.0 = ");
System.out.println(1+2.0);
if(1 + 2.0 == 3)
for(int i=0 ; i<l.size(); i++){
System.out.print(l.get(i));
}
}
}
运行结果:
Though 1 + 2.0 = 3.0
"1 + 2.0 == 3" is true