What is wrong with my java code

public class Solution {
public int removeDuplicates(ArrayList<Integer> a) {
    int k = 0;
    for(int i=1;i<a.size();i++)
        if(a.get(i) != a.get(k))
    return k+1;



here you are comparing Integers with !=.
This will work for small Integers that are internalized by the JVM but in general is wrong.
you should either cast the vales to int (primitive) or use !v1.equals(v2) instead of !=.


if (!a.get(i).equals(a.get(k)))


You have to remove extra integer from index k+1 to a.size()-1.

// remove sublist from index k+1 to index a.size()-1.