只打印一个标签列表java

时间:2014-10-23 15:34:30

标签: java arrays list

我有一个for循环,它打印以下内容:

Data(s):
 Hospital 1
Data(s):
 Hospital 2
Data(s): 
 Hospital 3
  and continue...

但是,我想只有一个标签,然后在不同的行中显示所有名称。

Such as:
   Data(s):
    Hospital 1
    Hospital 2
    Hospital 3
  and continue...

这是我现在拥有的Java代码:

 for(Data data : dataList){
    Data tabData_Hospital = new Data(data);
     tabData_Hospital.setLabel("Data(s): ");
     tabDataList.add(tabData_Hospital); 
 }

帮助表示赞赏..

1 个答案:

答案 0 :(得分:1)

在执行循环之前,您需要打印"Data(s): "

Data tabData_Hospital = new Data(data);
tabData_Hospital.setLabel("Data(s): ");

for(Data data : dataList){
    tabDataList.add(tabData_Hospital); 
}