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() 

Source Link

Document

Initializes a newly created String object so that it represents an empty character sequence.

Usage

From source file:Main.java

public static void main(String args[]) {
    String s1 = new String();
    System.out.println("String from java2s.com is" + s1);

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Object o = new String();
    Class sup = o.getClass().getSuperclass(); // java.lang.Object

}

From source file:Main.java

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

    // Get the length of str1 and str2 
    int len1 = str1.length();
    int len2 = str2.length();

    // Display the length of str1 and str2
    System.out.println("Length of  \"" + str1 + "\" = " + len1);
    System.out.println("Length of  \"" + str2 + "\" = " + len2);
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Object object = new String();

    Class cls = java.lang.String.class;
}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Object object = new String();
    // By way of an object
    Class cls = object.getClass();

}

From source file:Main.java

public static void main(String[] argv) throws Exception {
    Object object = new String();

    try {/*from   w  w w. jav a 2  s. com*/
        Class cls = Class.forName("java.lang.String");
    } catch (ClassNotFoundException e) {
    }
}

From source file:LengthOf.java

public static void main(String[] argv) {
    int ints[] = new int[3];
    Object objs[] = new Object[7];

    String stra = "Hello World";
    String strb = new String();

    // Length of any array - use its length attribute
    System.out.println("Length of argv is " + argv.length);
    System.out.println("Length of ints is " + ints.length);
    System.out.println("Length of objs is " + objs.length);

    // Length of any string - call its length() method.
    System.out.println("Length of stra is " + stra.length());
    System.out.println("Length of strb is " + strb.length());
}

From source file:MainClass.java

public static void main(String[] args) throws IOException {
    // 1. Reading input by lines:
    BufferedReader in = new BufferedReader(new FileReader("IOStreamDemo.java"));
    String s, s2 = new String();
    while ((s = in.readLine()) != null)
        s2 += s + "\n";
    in.close();/*  w w w  .  j a  va  2 s  .c om*/

}

From source file:ObjectUtilsTrial.java

public static void main(String[] args) {
    // Create ObjectUtilsTrial instance
    String one = new String();
    String two = one; // Same Reference
    String three = new String(); // New Object
    String four = null;/*from www .  ja v  a 2 s .  c o  m*/

    // four is null, returns DEFAULT
    System.out.print("1) If null return DEFAULT >>>");
    System.out.println(ObjectUtils.defaultIfNull(four, "DEFAULT"));

    // one and two point to the same object
    System.out.print("2) References to the same object >>>");
    System.out.println(ObjectUtils.equals(one, two));

    // one and three are different objects
    System.out.print("3) Check object references and not values >>>");
    System.out.println(ObjectUtils.equals(one, three));

    // toString method gets called
    System.out.print("4) toSring gets invoked >>>");
    System.out.println(one);

    // Object details displayed..toString is not called
    System.out.print("5) Display object details >>>");
    System.out.println(ObjectUtils.identityToString(one));

    // Pass null get empty string
    System.out.print("6) Pass null and get back an Empty string >>>");
    System.out.println("**" + ObjectUtils.toString(null) + "**");
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    BufferedReader stdin = new BufferedReader(new InputStreamReader(System.in));
    System.out.println(stdin.readLine());
    BufferedReader in = new BufferedReader(new FileReader("Main.java"));
    String s, s2 = new String();
    while ((s = in.readLine()) != null)
        s2 += s + "\n";
    in.close();/* w  ww  . j a  va2  s. c  o m*/
    StringReader in1 = new StringReader(s2);
    int c;
    while ((c = in1.read()) != -1)
        System.out.print((char) c);
    BufferedReader in2 = new BufferedReader(new StringReader(s2));
    PrintWriter out1 = new PrintWriter(new BufferedWriter(new FileWriter("IODemo.out")));
    int lineCount = 1;
    while ((s = in2.readLine()) != null)
        out1.println(lineCount++ + ": " + s);
    out1.close();
}