我對java比較陌生,在列表中需要幫助。 我的要求是,我將創建一個存儲用戶信息的列表。我正在使用字符串列表來實現這一點。現在我得到的輸出像[a,b,c,d,e,f,g,h]。這包含從「A到D」一條記錄和從「e到h」另一條記錄的2條記錄。取而代之的是,我需要輸出爲[a,b,c,d] [e,f,g,h]。另外,我需要使用突出顯示的單獨輸出來插入User對象,我需要遍歷輸出列表並將它們添加到新的User對象,例如:user1應該有[a,b,c,d]和用戶2有[e,f,g,h]等。 任何人都可以請讓我知道我該如何做到這一點。需要關於字符串列表的幫助
我的代碼片斷:
User testUser = null;
List<String> userList = new ArrayList<String>();
UserImpl u = new UserImpl();
String userCommonName = null, userEmail = null, userCanonicalName = ull,
userPrincipalType = null;
while (pit.hasNext()) {
testUser = (User) (pit.next());
userCommonName = testUser.getCommonName();
userEmail = testUser.getEmail();
userCanonicalName = testUser.getCanonicalName();
userPrincipalType = testUser.getPrincipalType();
userList.add(userCanonicalName);
userList.add(userCommonName);
userList.add(userPrincipalType);
userList.add(userEmail);
System.out.println(userList);// On printing this I am getting the
// above output which I need to split
// into separate records.
}
的單獨的記錄是在用戶列表必須被插回至另一用戶對象。
Iterator pit1 = userList.iterator();
while (pit1.hasNext()){
u.setCanonicalName(userCanonicalName);
u.setCommonName(userCommonName);
u.setEmail(userEmail);
u.setPrincipalType(userPrincipalType);
}
我有點迷失在這裏。任何幫助非常感謝!
無法得到您的問題。什麼是[a,b,c,d,e,f,g,h] – 2014-09-02 07:42:38