
solution1
use one loop
public int removeElement(int[] nums, int val){
int i = 0, j = nums.length  1;
while(i <= j){
if(nums[i] == val){
nums[i] = nums[j];
j;
}else{
i++;
}
}
return i;
} 
solution2
use two loop,
public int removeElement2(int[] nums, int val){
int i = 0, j = nums.length  1;
for(i = 0; i <= j; i++){
while(nums[i] == val && i <= j){
nums[i] = nums[j];
}
}
return (j+1);
}