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 + " ");
}
}
}
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 + " ");
}
}
}
Hi Ruchi,
ReplyDeleteCan I get the answer for this question .........
Write a code to extract only alphabets in a given string "@3FGT%^76JUH&"?
How to report bugs to the Selenium
ReplyDeleteHow to report bugs to the Selenium
ReplyDeleteVisit as many as you can as well as leave genuine feedback.
ReplyDeleteYou 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