22

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 ?

Grodriguez
  • 21,501
  • 10
  • 63
  • 107
Edu
  • 229
  • 1
  • 2
  • 3

3 Answers3

22

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:

  1. Try Connection.createArrayOf(). This might or might not be available, depending on the JDBC driver you are using.
  2. Write your own class that implements java.sql.Array. Here is an example for PostgreSQL.
  3. Some implementations, such as Oracle's, provide utility methods to work with arrays. Check the documentation of your JDBC driver.
Grodriguez
  • 21,501
  • 10
  • 63
  • 107
  • In the example of PostgreSQL, there is no method where we can pass the List or Arrays to get the java.sql.Array. – Shiva kumar Nov 16 '21 at 16:27
5

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)

Alan Geleynse
  • 24,821
  • 5
  • 46
  • 55
  • The problem is that i want to use a method in the jdbc driver framework that inserts arrays into sql databases this method is something like setArray(int arg0, Array arg1) and it only acepts the Array array type what should i do i tried another array types including arralist and nothing is working – Edu Nov 05 '10 at 18:27
  • anyone that can help me? – Edu Nov 05 '10 at 18:59
  • What method are you trying to use? – Alan Geleynse Nov 05 '10 at 19:08
  • Yes, Array has a set of static methods, so I was suggesting using Arrays.asList instead. But it now looks like he was trying to use java.sql.Arrays, so my answer does not apply. @Grodriguez seems to have the correct answer. – Alan Geleynse Nov 05 '10 at 19:47
0

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))

Community
  • 1
  • 1
EboMike
  • 76,846
  • 14
  • 164
  • 167
  • The problem is that i want to use a method in the jdbc driver framework that inserts arrays into sql databases this method is something like setArray(int arg0, Array arg1) and it only acepts the Array array type what should i do i tried another array types including arralist and nothing is working – Edu Nov 05 '10 at 18:26
  • What error do you get when you give it a string array? What error you get when you give it an ArrayList? – Daniel Standage Nov 05 '10 at 19:27