I have an array similar to that:
[null, null, 3, 4, null]
I want to change it to array similar to that:
[3, 4, null, null, null]
I know how to do it manually, but it looks ugly. Is there any built-in(with minimum custom code) way to do that? (maybe something with System.arraycopy)
I finished with something like this(thanks @Braj for idea):
@Test
public void test() {
Integer[] k = new Integer[]{null, null, 3, 2, 1};
k[1] = null;
Arrays.sort(k, new Comparator<Object>() {
public int compare(Object o1, Object o2) {
System.out.println(o1);
if (o1 == null) return 1;
else if(o2 == null) return -1;
else return 0;
}
});
assertArrayEquals(
new Integer[]{3, 2, 1, null, null},
k
);
}
If somebody interested there is a bigger problem which tried to solve with this code