代码示例:

int x = 23456;
System.out.println(x.toString().substring(2, 4));

结果:

'45'

解释:

  1. x.toString() 将整数 x 转换为字符串 '23456'。
  2. substring(2, 4) 从字符串 '23456' 中提取从索引 2 开始(包含索引 2)到索引 4 结束(不包含索引 4)的子字符串,即 '45'。

因此,代码输出 '45'。

Java 中 substring() 方法示例:从字符串中提取子字符串

原文地址: https://www.cveoy.top/t/topic/mXBA 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录