I am having trouble with my code... I am getting this error message: Cannot invoke toList() on the array type String [][]
How do i convert a String [][] to a List containing String []
in JAVA
frame.getContentPane().add(comboBoxGetFile);
btnGetInfo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String choice = comboBoxGetInfo.getSelectedItem().toString();
if(choice == "Customers") {
List<String[]> list = proxy.getAllCustomersInfo().toList();
}
}
})
I want it to fill a table, not print anything with a sys.out
After some changes I have this:
frame.getContentPane().add(comboBoxGetFile);
btnGetInfo.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent arg0) {
String choice = (String)comboBoxGetInfo.getSelectedItem();
if(choice.equals("Customers")) {
try {
List<String[]> list = Arrays.asList(proxy.getAllCustomersInfo());
//List<String[]> list = Arrays.stream(proxy.getAllCustomersInfo()).collect(Collectors.toList());
dtm.setColumnCount(4);
dtm.setColumnIdentifiers(colsForShowingCustomers);
for (String[] sa : list){
dtm.addRow(sa);
}
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
});
如果您使用的是 Java 8,请尝试以下操作:
List<String[]> list = Arrays.stream(proxy.getAllCustomersInfo()).collect(Collectors.toList());
The following code works just fine:
package eu.webfarmr;
import java.util.Arrays;
import java.util.List;
public class ListArray {
public static void main(String[] args) {
String[][] array = new String[][]{{"hello", "example", "one"},
{"cheerio", "another example", "two"}
};
List<String[]> list = Arrays.asList(array);
for (String[] a : list){
for (String s : a){
System.out.println(s);
}
}
}
}
It prints the following out:
hello
example
one
cheerio
another example
two
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.