[英]How can I get the items from a ListView and convert these items to an ArrayList?
[英]Get all items from ListView and convert to string Javafx?
我的Netbeans 8.1 Javafx項目中有一個ListView,我希望從ListView中檢索所有已添加到其中的項目,並將它們放在字符串中。 我不僅想要ListView中的選定項目,還想要每個項目。
我沒有嘗試過代碼的道歉,因為我真的不知道該怎么做。 預先感謝您的幫助和時間。
使用Collectors類(示例只是從那里復制並粘貼)。
// Convert elements to strings and concatenate them, separated by commas
String joined = listView.getItems().stream()
.map(Object::toString)
.collect(Collectors.joining(", "));
好吧,ListView確實有一個名為getItems()的方法。 您可能要從此開始。
通過將Observablelist轉換為List,我可以輕松地將其轉換為String以適應我的需求。
List<String> numbers = listView.getItems();
String listString = String.join(", ", numbers);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.