public static void copyToClipboard(final String string) {
    Preconditions.checkNotNull(string, "Error: String argument can not be null");

    final Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();

    clipboard.setContents(
        new StringSelection(string),
        new ClipboardOwner() {
          @Override
          public void lostOwnership(final Clipboard clipboard, final Transferable contents) {}
        });
  }
Copies a string to the system clipboard.

@param string The string to be copied to the system clipboard.
java/zylib/src/main/java/com/google/security/zynamics/zylib/general/ClipboardHelpers.java