我有一個需求,我需要做幾個Java調用並檢索必要的值。這些都是字符串。我需要用逗號分隔值將其寫入控制檯。如下圖所示:Java動態列標題
3,Till,,Till,Weiss,,
3,ugilad,,ugilad,ugilad,,
3,admintest,,admin,test,[email protected],
預期應該是:
userid,firstname,lastname,email
3,Till,,Till,Weiss,,
3,ugilad,,ugilad,ugilad,,
3,admintest,,admin,test,[email protected],
現在我需要將列添加到這些值。說:userId,firstName,lastName是這樣的。我如何使用Java代碼動態實現這一點?下面是我寫的代碼:
if (usersList.totalCount != 0 && usersList.totalCount >= 1) {
System.out.println("usersList.totalCount ----->"
+ usersList.totalCount);
for (KalturaUser user : usersList.objects) {
if (user != null) {
if (user.id != null) {
String userRole = getUserRole(user.id);
String cnum = getUserUniqueId(user.email);
// if (userRole != null) {
// if (userRole.equals("adminRole")
// || userRole
// .equals("privateOnlyRole")) {
// sb1.append(action);
if (user.id != null) {
sb.append(user.id);
} else {
sb.append(",");
}
String action = "1";
if (cnum != null) {
if (userRole == null) {
action = "3";
}
} else {
action = "3";
}
if (action != null) {
sb1.append(action);
}
if (cnum != null) {
sb1.append(",").append(cnum);
} else {
sb1.append(",").append(user.id);
sb1.append(",");
}
if (user.firstName != null) {
sb.append(",").append(user.firstName);
sb1.append(",").append(user.firstName);
} else {
sb.append(",");
sb1.append(",");
}
if (user.lastName != null) {
sb.append(",").append(user.lastName);
sb1.append(",").append(user.lastName);
} else {
sb.append(",");
sb1.append(",");
}
if (userRole != null) {
sb.append(",").append(userRole);
// sb1.append(",").append(userRole);
} else {
sb.append(",");
// action = "3";
// sb1.append(action);
}
// sb1.append("1");
if (user.email != null) {
sb.append(",").append(user.email);
sb1.append(",").append(user.email);
} else {
sb.append(",");
sb1.append(",");
}
if (userRole != null) {
sb1.append(",").append(userRole);
} else {
sb1.append(",");
}
// sb1.append("1");
if (user.partnerData != null) {
if (user.partnerData.startsWith("pw")
&& user.partnerData.length() == 43) {
sb.append(",");
}
if (user.partnerData.length() > 43) {
String partnerData = user.partnerData
.substring(44);
sb.append(",").append(partnerData);
}
if (!user.partnerData.startsWith("pw")) {
sb.append(",").append(user.partnerData);
}
}
sb.append(System.getProperty("line.separator"));
sb1.append(System.getProperty("line.separator"));
}
}
}
}
// System.out.println(sb);
System.out.println(sb1);
預期輸出的任何示例? –
什麼專欄?你想在控制檯中以表格形式打印嗎? –
@ Jean- UserID,FirstName,LastName,然後從下一行開始,像上面的示例輸出那樣,顯示相應列的值。我已經獲得了值,但如何添加標題是問題所在。 –