// indexOf作用是获取输入字符在整个字符串中的位置,从0开始;如果输入的字符不在字符串中则返回-1
// 获取字符串5的位置:4
System.out.println("123456".indexOf("5"));
// 获取字符5的位置:4
System.out.println("123456".indexOf('5'));
// 根据输入数字获取位置,如字符5对应的编码为 53,获取的位置为:4
// 使用indexOf(int ch)时ch是指字符对应的Unicode编码值;如你输入了5对应的字符不存在于123456中故返回-1
System.out.println("123456".indexOf(53));
// 可通过这里查询字符对应的unicode编码值:http://tool.chinaz.com/Tools/Unicode.aspx
System.out.println((int)'5');
字符5和数字5的区别
//int类型表示的是Unicode编码。而并非是5。5的Unicode编码是53,所以以下三种方式是同一结果
String str = "123456";
System.out.println(str.indexOf("5"));
System.out.println(str.indexOf('5'));
System.out.println(str.indexOf(53));