Example usage for java.lang StringBuilder append

List of usage examples for java.lang StringBuilder append

Introduction

In this page you can find the example usage for java.lang StringBuilder append.

Prototype

@Override
    public StringBuilder append(double d) 

Source Link

Usage

From source file:Main.java

public static void main(String[] arg) {

    StringBuilder buffer = new StringBuilder();
    CharSequence cs = "java2s.com";
    buffer.append(cs);
    System.out.println(buffer);/*from   w w w .  jav  a 2 s . co  m*/
}

From source file:Main.java

public static void main(String[] arg) {

    StringBuilder buffer = new StringBuilder();

    long l = 123456789098765L;
    buffer.append(l);

    System.out.println(buffer);//from ww  w.j  ava  2  s .  c o  m
}

From source file:Main.java

public static void main(String[] arg) {

    StringBuilder buffer = new StringBuilder();

    Object o = "from java2s.com";
    buffer.append(o);

    System.out.println(buffer);//w ww .j av a  2  s. co m
}

From source file:Main.java

public static void main(String[] argv) {
    JEditorPane jep = new JEditorPane();
    jep.setContentType("text/html");
    StringBuilder sb = new StringBuilder();
    sb.append("<b>Welcome</b>:<br><hr>");
    for (int i = 1; i <= 3; i++) {
        sb.append(create(i));/*from www.  j  a  v a  2s.  c  o m*/
    }
    sb.append("<hr>");
    jep.setText(sb.toString());
    jep.setEditable(false);
    jep.addHyperlinkListener(e -> {
        if (HyperlinkEvent.EventType.ACTIVATED.equals(e.getEventType())) {
            System.out.println(e.getURL());
            Desktop desktop = Desktop.getDesktop();
            try {
                desktop.browse(e.getURL().toURI());
            } catch (Exception ex) {
                ex.printStackTrace();
            }
        }
    });

    JFrame f = new JFrame();
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.add(jep);
    f.pack();
    f.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    String input = "ThisIsATest";

    // split into words
    String[] words = input.split("(?=[A-Z])");

    words[0] = capitalizeFirstLetter(words[0]);

    // join/* ww w .ja  va  2  s.  com*/
    StringBuilder builder = new StringBuilder();
    for (String s : words) {
        builder.append(s).append(" ");
    }

    System.out.println(builder.toString());

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    InetAddress ip = InetAddress.getLocalHost();
    System.out.println("Current IP address : " + ip.getHostAddress());

    NetworkInterface network = NetworkInterface.getByInetAddress(ip);
    byte[] mac = network.getHardwareAddress();
    System.out.print("Current MAC address : ");

    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < mac.length; i++) {
        sb.append(String.format("%02X%s", mac[i], (i < mac.length - 1) ? "-" : ""));
    }//from   ww w.jav  a  2 s . c  o m
    System.out.println(sb.toString());
}

From source file:StringBuilderDemo.java

public static void main(String[] argv) {

    String s1 = "Hello" + ", " + "World";
    System.out.println(s1);//from   ww  w. jav a 2s . c  o  m

    // Build a StringBuilder, and append some things to it.
    StringBuilder sb2 = new StringBuilder();
    sb2.append("Hello");
    sb2.append(',');
    sb2.append(' ');
    sb2.append("World");

    // Get the StringBuilder's value as a String, and print it.
    String s2 = sb2.toString();
    System.out.println(s2);

    // Now do the above all over again, but in a more
    // concise (and typical "real-world" Java) fashion.

    StringBuilder sb3 = new StringBuilder().append("Hello").append(',').append(' ').append("World");
    System.out.println(sb3.toString());
}

From source file:Main.java

public static void main(String[] args) {
    StringBuilder sb = new StringBuilder();
    for (int i = 0; i < 100; i++) {
        sb.append("this is a test. ");
    }//w w w .  j  av  a  2 s .co  m
    JFrame frame = new JFrame();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JTextPane newsTextPane = new JTextPane();
    newsTextPane.setContentType("text/html");
    newsTextPane.setEditable(false);
    newsTextPane.setText(sb.toString());

    JScrollPane scrollPane = new JScrollPane(newsTextPane);
    scrollPane.setVerticalScrollBarPolicy(javax.swing.ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
    frame.add(scrollPane);
    frame.setSize(300, 200);
    frame.setVisible(true);
}

From source file:Main.java

public static void main(String[] args) {
    // Create a String object
    String s1 = new String("Hello");

    // Create a StringBuilder from of the String object s1
    StringBuilder sb = new StringBuilder(s1);

    // Append " Java" to the StringBuilder's content
    sb.append(" Java"); // Now, sb contains "Hello Java"

    // Get a String from the StringBuilder
    String s2 = sb.toString(); // s2 contains "Hello Java"

}

From source file:Main.java

public static void main(String[] args) {
    JPanel gui = new JPanel(new BorderLayout());
    String HTML = "<html>" + "<head>" + "<style type=text/css>" + "body {"
            + "  background-image: http://www.java2s.com/style/download.png;" + "  background-repeat:no-repeat;"
            + "  background-position:left top;" + "  background-attachment: scroll;" + "  color: #BBBBBB;" + "}"
            + "</style>" + "</head>" + "<body>" + "<h1>Heading 1</h1>";
    String PARAGRAPH = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Aenean eu nulla urna. Donec sit amet risus nisl, a porta enim. Quisque luctus, ligula eu scelerisque gravida, tellus quam vestibulum urna, ut aliquet sapien purus sed erat. Pellentesque consequat vehicula magna, eu aliquam magna interdum porttitor. Class aptent taciti sociosqu ad litora torquent per conubia nostra, per inceptos himenaeos. Sed sollicitudin sapien non leo tempus lobortis. Morbi semper auctor ipsum, a semper quam elementum a. Aliquam eget sem metus.";

    gui.setPreferredSize(new Dimension(400, 100));

    StringBuilder sb = new StringBuilder();
    sb.append(HTML);
    for (int ii = 0; ii < 10; ii++) {
        sb.append("<h2>Header 2</h2>");
        sb.append(PARAGRAPH);// w  w w  . j  a  va2  s . c  o m
    }
    JEditorPane jep = new JEditorPane();
    jep.setOpaque(false);
    jep.setContentType("text/html");
    jep.setText(sb.toString());
    JScrollPane jsp = new JScrollPane(jep) {
        BufferedImage bg = new BufferedImage(350, 50, BufferedImage.TYPE_INT_RGB);

        @Override
        public void paintComponent(Graphics g) {
            super.paintComponent(g);
            g.drawImage(bg, 0, 0, this);
        }
    };
    jsp.getViewport().setOpaque(false);
    gui.add(jsp);

    Main bih = new Main();
    JFrame f = new JFrame();
    f.add(gui);
    f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    f.pack();
    f.setVisible(true);
}