简体   繁体   English

将 char 数组值分配给 char

[英]Assigning char array value to char

(in Java) I am trying to take a value out of my char array (在 Java 中)我试图从我的 char 数组中取出一个值

 char[] abc = {'a' , 'b' , 'c' , 'd' , 'e' , 'f'};

and assign it to a single char并将其分配给单个字符

 char currentChar = abc.[0];

and then ideally, I would replace 0 with and i for a for loop.然后理想情况下,我会将 0 替换为和 i 用于 for 循环。 Eclipse says Eclipse 说

"The type of the expression must be an array type but it resolved to Class" “表达式的类型必须是数组类型,但它解析为类”

How would I get variable currentChar to be equal to the character a ?我如何让变量 currentChar 等于字符 a ?

它一定要是

char currentChar = abc[0];

it should be它应该是

 char currentChar = abc[0];

when you are doing abc.当你在做abc. , it means its expecting class or object because of dot ,这意味着它的期望类或对象,因为点

Your syntax is just wrong - there doesn't have to a dot.你的语法是错误的 - 没有点。

Right would be:正确的是:

char currentChar = abc[0];

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM