I am trying to merge two arrays, remove duplicates and arrange in ascending order. Whenever I am trying to do this it's showing wrong.
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
class Main {
public static void main(String[] args) {
int a[] = { 1, 2, 3, 4 };
int b[] = { 1, 2, 3, 4, 5 };
HashMap<Integer, Integer> h1 = new HashMap<>();
for (int i = 0; i < a.length; i++)
h1.put(a[i], i);
for (int i = 0; i < b.length; i++)
h1.put(b[i], i);
for (Map.Entry<Integer, Integer> m1 : h1.entrySet())
System.out.print(m1.getKey() + " ");
System.out.println();
}
}
}
}
}