Java Program to find duplicate elements in an array?

Поделиться
HTML-код
  • Опубликовано: 18 окт 2024

Комментарии • 7

  • @indiantourism975
    @indiantourism975 4 года назад +1

    It's useful for me.... Thank you sir

  • @indlasubramanyam9510
    @indlasubramanyam9510 2 года назад +2

    Sandeep please cover all the scenarios .then only it will helped

  • @shariefrana
    @shariefrana 9 месяцев назад

    just say "!set.add(e)", the add method on set return false if the element already exists, this will simplify code further.

  • @akashnalawade4447
    @akashnalawade4447 2 года назад +2

    Try this one if you want to print no. of times of Duplicate element came
    public class Repeating {
    public static void main(String[] args) {
    int arr[] = { 10, 20, 30, 10, 10, 20, 40, 10 };

    Integer temp;
    HashMap map = new HashMap();
    for (int i = 0; i < arr.length; i++) {
    temp = (Integer) arr[i];
    if (map.get(temp) != null) {
    map.put(temp, map.get(temp) + 1);
    } else {
    map.put(temp, 1);
    }
    }
    for (Entry entry : map.entrySet()) {
    {
    if (entry.getValue() > 1) {
    System.out.print(entry.getKey());
    System.out.print("-:");
    System.out.print(entry.getValue());
    System.out.print("");

    }
    }
    }
    }
    }

  • @tejaswiadepu604
    @tejaswiadepu604 3 года назад +1

    If we have more than one duplicate, it will print double times.

  • @bhargavikasturi2027
    @bhargavikasturi2027 4 года назад +1

    Screen was not clear