How can I create a java.sql.Array of Strings?

Possible Duplicate:
How to create ArrayList (ArrayList<T>) from array (T[]) in Java

I have:

String[] time = {"22:22:22","22:22:23"};
Array asd = null;

How can I put something like asd=time ?


I assume that what you actually need is a java.sql.Array , since you mention jdbc and setArray in some of your comments.

Three options:

  • Try Connection.createArrayOf() . This might or might not be available, depending on the JDBC driver you are using.
  • Write your own class that implements java.sql.Array . Here is an example for PostgreSQL.
  • Some implementations, such as Oracle's, provide utility methods to work with arrays. Check the documentation of your JDBC driver.

  • The Array class is not an actual array. Instead it is a helper class that has static methods to help with arrays.

    You may be looking to use ArrayList or something like it. You could use it using List<String> asd = Arrays.asList(time)


    Array is an interface, not a class. Are you referring to ArrayList ?!

    Here is your answer: Create ArrayList from array

    new ArrayList<Element>(Arrays.asList(array))

    链接地址: http://www.djcxy.com/p/17630.html

    上一篇: 如何将File []数组内容添加到ArrayList中?

    下一篇: 我如何创建一个String.sql.Array?