• I want to write a string in Java. This is what I have

    [java]
    String str = "My String";
    [/java]

    However, this is what I get in the output
    String str = "My String";

    Can anyone help me out?

Viewing 1 replies (of 1 total)
  • String are a sequence of character in java. String are treated as a object. You can create string directly:-
    String greeting=”hello world”;

    You can also create string by using new keyword:-

    Public class stringDemo {
    public static void main(string args[]) {
    char[] Array={‘h’,’e’,’l’,’l’,’o’,’ ‘,’w’,’o’,’r’,’l’,’d’};
    string ar=new String(Array);
    System.out.print(ar);

Viewing 1 replies (of 1 total)
  • The topic ‘How to Write a String in Java’ is closed to new replies.