Java program to check if string is a palindrome : check palindrome string in java
Java Program to check whether number is Palindrome or not | Java Find Palindrome Number
Java program to check prime number : find prime number in Java
Java program to check if a number is Armstrong : Find Armstrong Number In Java
Insertion Sort in PHP With Example | How Does Insertion Sort Work in PHP
Linux du Command Example | Linux show disk usage
Linux Create Users : How To Create Users In Linux
C program to check if a number is Armstrong : Find Armstrong Number In C
If tutorials available on this website are helpful for you, please whitelist this website in your ad blocker😭 or Donate to help us ❤️ pay for the web hosting to keep the website running.
ArrayList का use करके duplicate elements को remove करने के लिए सबसे पहले सभी elements को एक new ArrayList में insert करेंगे , फिर उस list को iterate करके new list में insert करते रहेंगे। new list में insert करने से पहले contains()
method की help से हम check करेंगे कि element exist है या नहीं।
public class RemoveDuplicates {
public static void main(String[] args) {
// Array with duplicate elements
int[] arr = {1, 2, 3, 4, 2, 7, 8, 8, 3, 1};
// Create a list from the array
ArrayList<Integer> al = new ArrayList<>();
for (int i : arr)
al.add(i);
// Remove duplicates
ArrayList<Integer> newList = new ArrayList<>();
for (Integer element : al) {
if (!newList.contains(element)) {
newList.add(element);
}
}
// Finally iterate the list to print element.
for (Integer element : newList) {
System.out.print(element + " ");
}
}
}
Loading ...
Hi ! I'm Rahul Kumar Rajput founder of learnhindituts.com. I'm a software developer having more than 4 years of experience. I love to talk about programming as well as writing technical tutorials and blogs that can help to others. I'm here to help you navigate the coding cosmos and turn your ideas into reality, keep coding, keep learning :)
Get connected with me. :) LinkedIn Twitter Instagram Facebook