• + 6 comments

    Java 8 approach:

        String[] groups = Integer.toBinaryString(n).split("0");
        Integer result = Arrays.asList(groups)
            .stream()
            .map(group -> group.length())
            .max(Comparator.naturalOrder())
            .get();
        System.out.println(result);
    
    • max() is returning back an "Optional" however, there is no any test that check "0" as input value, so binary string is always having at least one "1", so it is save to call Optional.get() without checking "isPresented()".

    For me looks nice.. ;) However, you are welcome with improvements suggestions.