4 Replies Latest reply: Jan 13, 2008 11:53 AM by 807601

# Can someone teach me how to convert a int to a String array

I'v been trying to convert int to String array and its not working for me my codes are

String a[]={"10","24","5","3"};
int b=20;
a[0]=Integer.toString(b);

this code is ok when I drawString
but is't not ok when I want to compare the value in the string

exp.
String c[]={"20","2","4","7"}
if(a[0]==c[0])
//do something

• ###### 1. Re: Can someone teach me how to convert a int to a String array
Why don't you just declare an array of ints in the first place? Numbers should be stored as their correct type. If you want to compare then convert them first to equal types. To compare two Strings you should use the equals method

``````if (stringArray[0].equals(anotherStringArray[0]) ) {
//do something
}``````
http://www.exampledepot.com/egs/java.lang/CompareStr.html

Edited by: helloWorld on Jan 13, 2008 8:47 AM
• ###### 2. Re: Can someone teach me how to convert a int to a String array
Because the int is generated by a random function

Import java.util.Random;
Random random=new Random();
int RamValuse;
String a[]={"","","",""}

for(int i=0;i<=3;i++)
{
RamValue=Math.abs(random.nextInt()%10);
a=Integer.toString(RamValue);
}

I want to creat random int in the string array
• ###### 3. Re: Can someone teach me how to convert a int to a String array
Well if you want them as Strings then compare them with the equals method as pointed out above.
• ###### 4. Re: Can someone teach me how to convert a int to a String array
Thank you it worked like a charm