Different pairs of given value

 public class GivenValueDiffPairs {


public void findDiffPairs(List<Integer> values,int k){
Map<Integer,Integer> params =new HashMap<>();

int result=0;
for (Integer value : values) {
params.put(value,params.getOrDefault(value,0)+1);
}

for(Map.Entry<Integer,Integer> entryMap:params.entrySet()){
int key = entryMap.getKey();

if(k>0 && (params.containsKey(key+k))){
++result;

}
}

System.out.println(params);

System.out.println(result);

}

public static void main(String[] args) {
//1,1,3,4,5
//(3,4),(4,5)
new GivenValueDiffPairs().findDiffPairs(Arrays.asList(3,1,4,1,5),2);
}
}

Comments