Skip to content

Instantly share code, notes, and snippets.

@manjaykumardp
Created February 19, 2022 16:00
Show Gist options
  • Save manjaykumardp/7440fd2c4d7278fe764eebc3297a69ea to your computer and use it in GitHub Desktop.
Save manjaykumardp/7440fd2c4d7278fe764eebc3297a69ea to your computer and use it in GitHub Desktop.
Duplicate String in java
package com.manjay;
public class duplicate_element {
public static void main(String[] args) {
// String arr = new String[]{ } ;
String[] arr = new String[]{"b","a","a","a"};
System.out.println("Duplicate elements in given array: ");
//Searches for duplicate element
for (int i = 0; i < arr.length; i++) {
for (int j = i + 1; j < arr.length; j++) {
if (arr[i].equals(arr[j])) {
System.out.print(arr[j] + " ");
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment