我想得到:
String[] phoneNos= {"07064267499","07064267499","07064267499"};
来自:
ArrayList<Object> phoneNos = [0803406914, 08167337499, 0803377973] ;
这是我的代码段:
public ArrayList < Object > getPhoneNo() {
ArrayList < Object > phoneNos = new ArrayList < Object > ();
try {
Statement stmt = con.createStatement();
ResultSet result = stmt.executeQuery("SELECT Phone_No FROM paient_details");
while (result.next()) {
phoneNos.add(result.getString(1));
}
} catch (SQLException e) {
System.out.println(e.getMessage());
}
return phoneNos;
}
答案 0 :(得分:2)
您可以使用toArray()
对象中的List
方法:
String[] phoneNosArray = new String[phoneNos.size()];
phoneNosArray = phoneNos.toArray(phoneNosArray);
答案 1 :(得分:1)
首先,将您的ArrayList
更改为:
ArrayList<String> phoneNos = new ArrayList<String>();
因为您将String
存储在其中。
然后你可以得到相应的数组:
String[] arr = phoneNos.toArray(new String[phoneNos.size()]);