Friday 3 January 2014

program to fetch unique elements from Array.

Write a program to fetch unique elements from Array.

package programs;

import java.util.LinkedHashSet;
import java.util.Set;

public class Arrayuniqno {
public static void main(String[] args) {
int[] array1 = { 1, 1, 2, 1, 3, 4, 5, 8, 8, 8, 8 };

System.out.println("Original Array1  Elements1:");
for (Integer x : array1) {
System.out.print(x + " ");
}
Set<Integer> UniqueNumbers = new LinkedHashSet<Integer>();
for (int x : array1) {
UniqueNumbers.add(x);
}
System.out.println("");
System.out.println("Array2 with Unique Elements: ");
Object[] array2 = UniqueNumbers.toArray();
for (Object x : array2) {
System.out.print(x + " ");
}
}
}

4 comments:

  1. Hi Ruchi,

    Can I get the answer for this question .........
    Write a code to extract only alphabets in a given string "@3FGT%^76JUH&"?

    ReplyDelete
  2. How to report bugs to the Selenium

    ReplyDelete
  3. How to report bugs to the Selenium

    ReplyDelete
  4. Visit as many as you can as well as leave genuine feedback.
    You have to break down exactly how you want to earn money online.
    It helps if you are a webmaster, because
    then you can promote your own product on your own site.


    my page ... ways to make money online

    ReplyDelete