我想得到:

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;
}

最佳答案

您可以从toArray()对象使用List方法:

String[] phoneNosArray = new String[phoneNos.size()];
phoneNosArray = phoneNos.toArray(phoneNosArray);

关于java - 从Arraylist创建字符串数组,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/33329037/

10-13 22:47