Java
Programming and Technical
Programming
Arrays
Can we create a String object by using an array of characters?
[1] If Yes, then how?
[2] If No, then why?
Read Solution (Total 5)
-
- Yes, Definitely we can create a String object in java by using an array of characters.
This is an example of that
char [ ]city = {'B','a','n','g','a','l','o','r','e'};
String CityName = new String(city);
The above 2 lines create a String object with content "Bangalore".Put this 2 lines inside the main() method and include an output statement to print the String contents.After that compile & run the program. - 8 years agoHelpfull: Yes(6) No(0)
- yes,because if we create the char array like..char s[]={'h','e','l','l','o'};
String str=new String(s);
System.out.println(s);
o/p:- is hello - 8 years agoHelpfull: Yes(5) No(0)
- char [] c = {'j', 'a', 'v', 'a'};
String data = new String(c); // creates string "java" - 8 years agoHelpfull: Yes(1) No(0)
- I am not sure but I presume there is a constructor which takes character array and build string object
check String constructors may be you will get an idea - 8 years agoHelpfull: Yes(0) No(1)
- yes ,
chr[]=('r','h','l'); - 8 years agoHelpfull: Yes(0) No(0)
Java Other Question