如何在Java中为字符串和整数添加循环

问题描述 投票:0回答:1

我有此代码:

int[] arr = new int[] {0254,0156,0641,0974,0112};

html.append("<table border=1 valign=\"center\" width=270 height=30 
background=\"L2UI_CT1.Windows_DF_Drawer_Bg\">");
html.append("<tr>");

for(int i:arr){ 
    html.append("<td width=30><img src=\"icon.customtex_" + i + "\" width=32 height=32></td>"); 
    html.append("<td align=\"center\" width=290>Name 1</td>");
}

html.append("</tr>");
html.append("</table>");

我需要更改“名称1”等效的INT结果

例如:

String[] arr2 = new String[] {"Name 1","Name 2","Name 3","Name 4","Name 5"};
java html arrays loops each
1个回答
0
投票

您只需要这样做:

for(int i=0; i<arr.length; i++){ 
    html.append("<td width=30><img src=\"icon.customtex_" + arr[i] + "\" width=32 height=32></td>"); 
    html.append("<td align=\"center\" width=290>" + arr2[i] + "</td>");
}
© www.soinside.com 2019 - 2024. All rights reserved.