I am populating JSON parsed data into Dialog, like this:
String[] colors = new String[] {cArrayList.toString()};
Log.d("colors::-", Arrays.toString(colors));
GETTING
EXPECTED
asked Sep 19, 2015 at 5:02
Oreo
2,6048 gold badges40 silver badges63 bronze badges
3 Answers 3
As per your requirement you can do following if your cArrayList is ArrayList
String[] colors = new String[cArrayList.size()] ;
for(int i=0;i<cArrayList.size();i++)
{
colors[i]=cArrayList.get(i);
}
Alternatively, you can use the more concise and faster approach:
String[] colors = cArrayList.toArray(new String[cArrayList.size()]);
Sign up to request clarification or add additional context in comments.
4 Comments
Oreo
getting NPE at this line checkedColors[which] = isChecked; check this: pastebin.com/81PBd4Rd
Pavan
where you defining checkedColors i dint see initialization of checkedColors
Oreo
global boolean[] checkedColors = null; @Pavan check this : pastebin.com/81PBd4Rd
Oreo
Let us continue this discussion in chat.
Like in Core Java you convert int[] to List<Integer> same as the code shows below:
int[] ints = {100,1000,10000};
List<Integer> ls = new ArrayList<Integer>();
for (int index = 0; index < ints.length; index++)
{
ls.add(ints[index]);
}
View reference How to convert int[] into List in Java?
answered Sep 19, 2015 at 5:16
Divyesh Kanzariya
3,8093 gold badges48 silver badges47 bronze badges
Comments
To convert your integer value to a string use:
String.valueOf(insert your integer value here);
sschrass
7,1606 gold badges47 silver badges66 bronze badges
answered Sep 19, 2015 at 5:27
akhil batlawala
1,0661 gold badge10 silver badges31 bronze badges
1 Comment
akhil batlawala
It convert your integer value to string
lang-java
String[] colors = new String[]{ cArrayList.size() };What are you attempting to do here? Create an array of Strings of that size or put the size of that arraylist as the first element in the colors array?