code: static int[] toArray(BitSet set) {
          int[] vertices = new int[set.cardinality()];
          int i = 0;
  
          // fill the cyclic vertices with the bits that have been set
          for (int v = 0; i < vertices.length; v++) {
              if (set.get(v)) {
                  vertices[i++] = v;
              }
          }
  
          return vertices;
      }
docs: Convert the set bits of a BitSet to an int[].
  
  @param set input with 0 or more set bits
  @return the bits which are set in the input