I used the code below. It uses a string variable
String[] parts = cmdAndArgs.split("/");
and another variable
String cmd = parts[0];
String response = "okayh";
String[] parts = cmdAndArgs.split("/");
String cmd = parts[0];
if (cmd.equals("analogWrite"))
{
if(parts[1].equals("Speaker"))//addedline
{
int value=3;
arduino.analogWrite(value, Integer.parseInt(parts[2]));//addedline
}
response = "";
System.out.print ("" +cmdAndArgs.split("/"));
I wanted to view the values in the variable cmdAndArgs
, so i did
response = "";
System.out.print ("" +cmdAndArgs.split("/"));
But it gave the following output
[Ljava.lang.String;@964130
I cannot understand what the output is or how I can view the String
passed in that variable?
Split returns an array. You are just printing the array object where you have to print the array contents.
Probably you want
System.out.print (Arrays.toString(cmdAndArgs.split("/")));
or you can iterate over the array to print each string in it.
For printing the array you have to do a foreach like this
for (String cmd : cmdAndArgs){
System.our.println (cmd);
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.