fork download
  1. import java.util.*;
  2.  
  3. public class Main {
  4. public static void main(String[] args) {
  5. List<Integer> arr = new ArrayList<>(Arrays.asList(3, 3, 2, 3));
  6. int x = 0;
  7. for (int i : arr) {
  8. if (Collections.frequency(arr, i) == 1) {
  9. x = i;
  10. break;
  11. }
  12. }
  13. System.out.println("The element with single occurrence is " + x);
  14. }
  15. }
Success #stdin #stdout 0.11s 39876KB
stdin
Standard input is empty
stdout
The element with single occurrence is 2