I want to convert binary List to binary int[]. My code is as is below:
public class BinListToIntArr {
public static void main(String[] args) {
List<String[]> arrList = new ArrayList<>();
//fill it
arrList.add(new String[] {"0011","1100","1111","1111","0000"});
arrList.add(new String[] {"0101","1111","1010","0000","0101"});
arrList.add(new String[] {"1111","1010","0000","0101","1111"});
arrList.add(new String[] {"1010","0000","1111","0101","1100"});
arrList.add(new String[] {"0000","1110","1100","0001","0011"});
//convert it
ArrayList<Integer> ints = new ArrayList<>();
for (String[] array : arrList) {
for (String str : array) {
ints.add(Integer.parseInt(str));
}
}
Integer[] result = ints.toArray(new Integer[] {});
for (int i : result){
System.out.println(i);
}
}
}
The result supposed to be:
0011
1100
1111
1111
0000
1010
1111
1010
0000
1010
1111
1010
0000
1010
1111
1010
0000
1111
1010
1100
0000
1110
1100
1000
1100
But I got this result:
11
1100
1111
1111
0
101
1111
1010
0
101
1111
1010
0
101
1111
1010
0
1111
101
1100
0
1110
1100
1
11
In which part I made a mistake? Is there anybody can help? Because no matter I tried, 0 in String always disappear when I convert it into int. Is it possible to make 0 in String not disappear when we convert to int? If yes, how?