code: private void addKey(SelectionKey k) {
          assert Thread.holdsLock(keyLock);
          int i = 0;
          if ((keys != null) && (keyCount < keys.length)) {
              // Find empty element of key array
              for (i = 0; i < keys.length; i++)
                  if (keys[i] == null)
                      break;
          } else if (keys == null) {
              keys =  new SelectionKey[3];
          } else {
              // Grow key array
              int n = keys.length * 2;
              SelectionKey[] ks =  new SelectionKey[n];
              for (i = 0; i < keys.length; i++)
                  ks[i] = keys[i];
              keys = ks;
              i = keyCount;
          }
          keys[i] = k;
          keyCount++;
      }
docs: -- Utility methods for the key set --