No Duplicate Elements in an Array

import java.util.*;

/**
*
*/

/**
* @author asharda
*
*/
public class NoDup {

/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub

printdup();
}

public static void printdup()
{
int a[]={1,1,2,3,4,5,4,1};
ArrayList<Integer>list=new ArrayList<Integer>();
for(int i=0;i<a.length-1;i++)
{
if(!(list.contains(a[i])))
{
list.add(a[i]);
}
}//end of for loop

System.out.println(“No duplicate elements of the array are”);
for(int i:list)
System.out.println(i);
}
}

Advertisements

About qainterviews

Software Geek,QA Expert,Blogger
This entry was posted in Uncategorized and tagged , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s