如何使用 Java 字符串方法返回所选数量的字符?

huangapple go评论80阅读模式
英文:

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());

huangapple
  • 本文由 发表于 2020年10月2日 07:00:46
  • 转载请务必保留本文链接:https://go.coder-hub.com/64164228.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定