Java String.equals with for each和for循环 String[]rgb=新字符串[3]; rgb[0]=Integer.toHexString(color.getRed()); rgb[1]=Integer.toHexString(color.getGreen()); rgb[2]=Integer.toHexString(color.getBlue()); 用于(字符串el:rgb) { 如果(el.等于(“0”)) { el=“00”; } } 对于(int i=0;i
对于每个Java String.equals with for each和for循环 String[]rgb=新字符串[3]; rgb[0]=Integer.toHexString(color.getRed()); rgb[1]=Integer.toHexString(color.getGreen()); rgb[2]=Integer.toHexString(color.getBlue()); 用于(字符串el:rgb) { 如果(el.等于(“0”)) { el=“00”; } } 对于(int i=0;i,java,for-loop,foreach,Java,For Loop,Foreach,对于每个循环,字符串el实际上不是对数组rgb的引用。它只保存数组中给定索引的值。因此,在这种情况下,必须使用正常的for循环来修改数组的内容;否则el的内容是just覆盖循环的每个迭代 直观的解释: String[] rgb = new String[3]; rgb[0] = Integer.toHexString(color.getRed()); rgb[1] = Integer.toHexString(color.getGreen()); rgb[2] = Integer.toHexSt
循环,字符串el
实际上不是对数组rgb
的引用。它只保存数组中给定索引的值。因此,在这种情况下,必须使用正常的for
循环来修改数组的内容;否则el
的内容是just覆盖循环的每个迭代
直观的解释:
String[] rgb = new String[3];
rgb[0] = Integer.toHexString(color.getRed());
rgb[1] = Integer.toHexString(color.getGreen());
rgb[2] = Integer.toHexString(color.getBlue());
for(String el : rgb)
{
if(el.equals("0"))
{
el = "00";
}
}
for(int i = 0; i<3; i++)
{
if(rgb[i].equals("0"))
{
rgb[i] = "00";
}
}
String[]i=新字符串[]{“你好”,“你好”};它不会在foreach循环中“运行false”-当您提问时,请确保检查您所做的断言,通常这样做可以让您自己回答问题。@Shahzeb color是一个保存java.awt类型的变量。Color@pvg是的,退一步质疑你的假设总是好的,谢谢你的提醒!
String[] i = new String[]{"Hi", "Hello"}; <------- Contains two indexes.
for(String str : i){
str = str + "!";
}