Removing the duplicate elements from an array is the same as printing the unique elements of an array. Notes:- If we write boolean[ ] flag = new boolean[ size ] ; in java, it creates an array of booleans where false present in all positions by default. We don't have to assign value to flag array elements exclusively. Java 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 public class RemoveDuplicate{ public static void main (String []args){ int [] arr = { 1 , 2 , 3 , 6 , 3 , 3 , 3 , 4 , 2 }; boolean [] flag = new boolean [arr. length ]; for ( int i= 0 ; i<arr. length ; i++) if (!flag[i]) for ( int j=i+ 1 ; j<arr. length ; j++) ...
This blog contains coding/programming and interview questions of MNCs like TCS, Wipro, Infosys, Capgemini, Mindtree, Amazon, Google, Facebook, Flipkart, Cisco, HP, Dell, etc. with placement preparation guides.