tags:

views:

223

answers:

7

please explain whats happening in this line of code . specialy what is args[0].tocharArray

char[] password = args[0].toCharArray();
+3  A: 

args[0] is presumably a String array. Thus it is a call to the method String.toCharArray() which converts a String to an array of chars.

EDIT: Corrected my answer after comment.

moxn
You mean that `args` is a String array, and `args[0]` is a String...
Yuval
Whoops, yes right...
moxn
+2  A: 

It converts the first item of the args array (presumably, the first command line argument passed to the main method, which is of string type) to an equivalent array of chars (an array containing all the chars that build up the string).

Konamiman
A: 

args[0] - representing a string toCharArray() - convert this string to char array

alex.climov
+1  A: 

args is an array.

The type of the array contains a function called toCharArray which returns an array of characters. NOTE: args is most likely an array of strings

So it takes the string in args[0] and creates an array of characters which represents that string.

tster
+4  A: 
erickson
+7  A: 

char[] is your datatype. "char" is a single 16 bit character, and char[] is a character array.

args[0] is the first argument that's passed to the program.

.toCharArray(); converts that argument to a character array.

This line of code is basically taking an argument, turning it into a character array, and storing it in "password" which is a character array.

Jeremy Morgan
+1 for mind reading. How do you know args refers to the args in main ? ...
OscarRyz