Example usage for java.lang String String

List of usage examples for java.lang String String

Introduction

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

Prototype

public String(StringBuilder builder) 

Source Link

Document

Allocates a new string that contains the sequence of characters currently contained in the string builder argument.

Usage

From source file:MainClass.java

public static void main(String args[]) {
    String s1 = new String("hello");
    String s2 = new String("GOODBYE");
    String s3 = new String("   spaces   ");

    System.out.printf("s1 = %s\ns2 = %s\ns3 = %s\n\n", s1, s2, s3);

    // test toLowerCase and toUpperCase
    System.out.printf("s1.toUpperCase() = %s\n", s1.toUpperCase());
    System.out.printf("s2.toLowerCase() = %s\n\n", s2.toLowerCase());

}

From source file:Main.java

public static void main(String[] args) {
    String s = new String(revStr("hello brave new world"));
    String st = new String(revWords("hello brave new world"));
    System.out.println(s);//  w  ww .  jav a2 s .c o m
    System.out.println(st);
}

From source file:Main.java

public static void main(String[] args) {
    String str = new String("Apple");

    int index = str.indexOf('p'); // index will have a value of 1
    System.out.println(index);// w  ww  . jav  a2s  . co m

    index = str.indexOf("pl"); // index will have a value of 2
    System.out.println(index);
    index = str.lastIndexOf('p'); // index will have a value of 2
    System.out.println(index);

    index = str.lastIndexOf("pl"); // index will have a value of 2
    System.out.println(index);

    index = str.indexOf("k"); // index will have a value of -1
    System.out.println(index);
}

From source file:Main.java

public static void main(String[] args) {
    byte b = 65;//from  www.  j a va 2 s . c o m

    System.out.println(new String(new byte[] { b }));

}

From source file:Main.java

public static void main(String args[]) {
    String s1 = "demo2s.com";
    String s2 = new String(s1);

    System.out.println(s1 + " equals " + s2 + " -> " + s1.equals(s2));
    System.out.println(s1 + " == " + s2 + " -> " + (s1 == s2));
}

From source file:EqualsNotEqualTo.java

public static void main(String args[]) {
    String s1 = "Hello";
    String s2 = new String(s1);

    System.out.println(s1 + " equals " + s2 + " -> " + s1.equals(s2));
    System.out.println(s1 + " == " + s2 + " -> " + (s1 == s2));
}

From source file:MakeString.java

public static void main(String args[]) {
    char c[] = { 'J', 'a', 'v', 'a' };
    String s1 = new String(c);
    String s2 = new String(s1);

    System.out.println(s1);/*from w  w  w. ja v a2s . c o m*/
    System.out.println(s2);
}

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) {
    String s1 = "Hello World";
    String s2 = new String("Hello World");

    if (s1.equals(s2)) {
        System.out.println("String is equal");
    } else {//from  w  w  w .  j  a  v a  2  s .c  om
        System.out.println("String is unequal");
    }
    if (s1 == s2) {
        System.out.println("String is equal");
    } else {
        System.out.println("String is unequal");
    }
}

From source file:Main.java

public static void main(String args[]) {
    byte ascii[] = { 65, 66, 67, 68, 69, 70 };

    String s1 = new String(ascii);
    System.out.println(s1);//from   ww w  .  ja v a  2  s . c  o m

}