Java子字符串不起作用 [英] Java substring not working
本文介绍了Java子字符串不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
请原谅,我是Java的新手,有一个非常基本的问题.我有一个字符串,想要它的子字符串,例如:
Forgive me, I'm new to Java and have an extremely basic question. I have a string and want a substring of it, for example:
String str = "hello";
str.substring(1);
System.out.println(str);
我得到的是原始的"hello"
,而不是得到"ello"
,为什么会这样呢?谢谢.
Instead of getting "ello"
I get the original "hello"
, any idea why this is? Thanks.
推荐答案
在Java中无法更改字符串,因此您需要像这样重新分配子字符串:
Strings cannot be changed in Java, so you will need to re-assign the substring as such:
str = str.substring(1)
与单独调用方法相反.
这篇关于Java子字符串不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文