0
我需要創建一個鏈表,並用容器中的「容器」和「元素」填充它。用其他列表中的單獨元素和元素填充java列表的最佳方法是什麼?
這是我的代碼:
public List<WebElement> getExpectedElements(){
List<WebElement> list = new LinkedList<WebElement>(Arrays.asList(
inetConnection,
wiredConnection,
phonesConnection,
usbConnection,
wifiConnection
));
list.addAll(inetConnection.getExpectedElements());
list.addAll(wiredConnection.getExpectedElements());
list.addAll(phonesConnection.getExpectedElements());
list.addAll(usbConnection.getExpectedElements());
list.addAll(wifiConnection.getExpectedElements());
return list;
}
是否有在java中的任何方法,使之更好(更簡潔,乾燥等)?
你能繞過列表填充它的對象? –
「更好?」是什麼意思? –
@SotiriosDelimanolis它不是通信對象的責任......至少在我的對象模型中... – yashaka