public static Set<Integer> foreach(BitSet x){
  Set<Integer> result=new TreeSet<Integer>();
  for (int i=0; i < x.length(); i++)   if (x.get(i))   result.add(i);
  return result;
}

public static Set < Integer > foreach ( BitSet x ) { Set < Integer > result = new TreeSet < Integer > ( ) ; for ( int i = 0 ; i < x . length ( ) ; i ++ ) if ( x . get ( i ) ) result . add ( i ) ; return result ; }
cast a bitset , so to speak , to an iterable set .
