[英]How to change elements in the ArrayList to a different object type?
I have an ArrayList<Character>
. 我有一个
ArrayList<Character>
。 How do I change the elements inside the array into integers? 如何将数组内的元素更改为整数? The code is in Java.
该代码使用Java。
Example: 例:
private ArrayList<Character> arrayList;
I tried Integer.parseInt()
like this: 我像这样尝试了
Integer.parseInt()
:
Integer.parseInt(arrayList, arrayList.get(0));
But the parseInt
only works for strings. 但是
parseInt
仅适用于字符串。
看文档 ,您可以只使用.charValue()
并将其转换为int
(int)(arrayList.get(0).charValue());
You are trying to convert a character to int while the parseInt
method works only for Strings. 您正在尝试将字符转换为int,而
parseInt
方法仅适用于字符串。 Try this: 尝试这个:
Integer.parseInt(arrayList.get(0).toString());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.