How to Copy a String to Clipboard in Java

Description:

In this post, we show a simple method that shows to copy any String to clipboard in java


Code:

import java.awt.datatransfer.*;
import java.awt.Toolkit;

public class StringToClipBoard {
 public static void main(String[] args) {
 
 //Enter your string
 String myString = "www.javaproblems.com";

 //Those methods will do all the work
 StringSelection stringSelection = new StringSelection (myString);
 Clipboard clpbrd = Toolkit.getDefaultToolkit ().getSystemClipboard ();
 clpbrd.setContents (stringSelection, null);

 //You're done!
 }
}


4 comments :

  1. Your good knowledge and kindness in playing with all the pieces were very useful. I don’t know what I would have done if I had not encountered such a step like this.
    Data Science training in Chennai
    Data science training in Bangalore
    Data science training in pune
    Data science online training
    Data Science Interview questions and answers
    Data Science Tutorial

    ReplyDelete
  2. Useful information.I am actual blessed to read this article.thanks for giving us this advantageous information.I acknowledge this post.and I would like bookmark this post.Thanks
    Data Science Training in Indira nagar
    Data Science Training in btm layout
    Data Science Training in Kalyan nagar
    Data Science training in Indira nagar
    Data science training in bangalore

    ReplyDelete
  3. It is amazing and wonderful to visit your site.Thanks for sharing this information,this is useful to me...data science courses

    ReplyDelete

Follow Me

If you like our content, feel free to follow me to stay updated.

Subscribe

Enter your email address:

We hate spam as much as you do.

Upload Material

Got an exam, project, tutorial video, exercise, solutions, unsolved problem, question, solution manual? We are open to any coding material. Why not upload?

Upload

Copyright © 2012 - 2014 Java Problems  --  About  --  Attribution  --  Privacy Policy  --  Terms of Use  --  Contact