int[] arr={1,3,0,6,3,0,5,8,9,0,51,0,28,0,36,23};
![在这里插入图片描述](https://img-blog.csdnimg.cn/20210925205340266.png?x-oss-process=image/watermark,type_ZmFuZ3poZW5naGVpdGk,shadow_10,text_aHR0cHM6Ly9ibG9nLmNzZG4ubmV0L3F3MzI3NjQyNTQwNQ==,size_16,color_FFFFFF,t_70)
public static void main(String[] args) {
// 定义方法,将数组int[] arr={1,3,0,6,3,0,5,8,9,0,51,0,28,0,36,23};去掉0变成一个新数组,并升序排列
int[] arr={1,3,0,6,3,0,5,8,9,0,51,0,28,0,36,23};
System.out.println(Arrays.toString(parse(arr)));
}
private static int[] parse(int[] arr) {
int len=0;
for (int num : arr) {
if(num!=0)
len++;
}
int[] arr1=new int[len];
for (int n : arr) {
if(n!=0)
arr1[–len]=n;
}
Arrays.sort(arr1);
return arr1;
}