[英]printing a value from a string variable
I used the code below. 我用下面的代码。 It uses a string variable
它使用字符串变量
String[] parts = cmdAndArgs.split("/");
String [] parts = cmdAndArgs.split(“/”);
and another variable 和另一个变量
String cmd = parts[0];
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 我想查看变量
cmdAndArgs
的值,所以我做了
response = "";
System.out.print ("" +cmdAndArgs.split("/"));
But it gave the following output 但它给出了以下输出
[Ljava.lang.String;@964130
[Ljava.lang.String; @ 964130
I cannot understand what the output is or how I can view the String
passed in that variable? 我无法理解输出是什么或如何查看该变量中传递的
String
?
Split returns an array. Split返回一个数组。 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 为了打印数组,您必须像这样进行一次foreach
for (String cmd : cmdAndArgs){
System.our.println (cmd);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.