Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to convert from Array<String> to String[] in Java

Tags:

java

I have to get a part of my content provider query in a String[] format. Currently I use:

        String[] selectionArgs = {"",""};
    selectionArgs[0] = Integer.toString(routeScheduleID);
    selectionArgs[1] = runDate.toString();

But in this case I have an unknown number of elements.

How can I change the number at runtime (or use something like an Array and convert back to String[]. Is this possible?

like image 276
WaterBoy Avatar asked Nov 22 '25 13:11

WaterBoy


2 Answers

You can use List<String> to get your data and then get the array out of it:

List<String> lst = new ArrayList<String>();
lst.add(Integer.toString(routeScheduleID);
lst.add(runDate.toString());
lst.add(...);
...

String[] selectionArgs = lst.toArray(new String[lst.size()]);
like image 127
Aleks G Avatar answered Nov 25 '25 05:11

Aleks G


You can use List for this. A List of Strings like this - List<String> str = new ArrayList<String>();

like image 33
Pramod Kumar Avatar answered Nov 25 '25 05:11

Pramod Kumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!