I'm trying to convert array of numbers to array of words for example:
{1,2} will converted to {"one","two"}
so this is the code that I write in java:
public static void main(String[] args) {
ArrayList<Integer> list1 = new ArrayList<>(Arrays.asList(1,2));
Integer [] list1Array = list1.toArray(new Integer[0]);
int numLength2 = list1.size();
for(int i = 0; i < numLength2; i++){
System.out.println(list1Array[i]);
}
System.out.println(numLength2);
String n2 = "";
for(int j = 0; j < numLength2; j++) {
int element = list1.get(j);
System.out.println(element);
switch (element) {
case '1': {
n2 = n2 + "one";
break;
}
case '2': {
n2 = n2 + "two";
break;
}
default: {
n2 = n2 + "zero";
}
}
}
System.out.println(n2);
}
}
It works fine except the last print:
System.out.println(n2);
The output here is zerozero while it should be onetwo. What's problem with code?