Saturday, 10 June 2017

How To Remove Duplicate Value from an Array?


package com.tutorial4u;

public class RemoveDuplicate {
       public static void main(String[] args) {
              int array[] = {1,2,2,3,4,4,5,6,6,7};
              for(int i=0;i<array.length;i++){
                     for(int j=i+1;j<array.length;j++){
                            if(array[i]==array[j]){
                                  i++;
                                j=i+1;
                            }
                     }
                     System.out.print(" "+array[i]);
              }
       }


}

Output:
     
 1 2 3 4 5 6 7

No comments:

Post a Comment

No of Occurrence in Array

package com.tutorial4u; import java.util.HashMap; /************************************************************  No of Occurrence in Array...