英文:
How to use a java string method to return a selected amount of characters?
问题
我正在努力弄清楚如何在我的Java字符串中返回选定数量的字符。
在Python中,就像这样
String randomVar = "hello";
System.out.println(randomVar.substring(1));
输出将是 "ello"。
我如何在Java中实现相同的功能?
谢谢!
英文:
I am trying to figure out how to return a selected amount of characters in my java string.
In Python, it is just like
randomVar = "hello"
print(randomVar[1:])
and the output would be "ello".
How do I do the same thing in java?
Thank you!
答案1
得分: 0
这可以通过 substring()
实现。
String a = "hello";
System.out.println(a.substring(1, a.length()));
英文:
This can be accomplished with substring()
String a = "hello";
System.out.println(a.substring(1, a.length());
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论