- public class demo {
- public static void main(String[] args) {
- // TODO Auto-generated method stub
- char[] list=new char[]{'s','f','g','d','q','4','7','k'};
- char flag='s';
- String str=new String(list);
- System.out.println(str.indexOf(flag));
- System.out.println("............................");
- String str1=list.toString();
- System.out.println(str1.indexOf(flag));
- }
- }
复制代码
运行结果:
0
............................
-1
问题:list.toString和new String(list)不都是将字符数组转化为字符串吗?但是为什么他们的indoxOf返回的数值不同呢? |