如何从参数 Java 解析字符串?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/13407871/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 12:36:52  来源:igfitidea点击:

How to parse a string from arguments Java?

javastringparsingarguments

提问by Jake Orben

I have been trying to parse a string from arguments, I have tried

我一直试图从参数中解析一个字符串,我试过了

String.parseString(args[0]);

what exactly am I doing wrong?

我到底做错了什么?

回答by Reimeus

As the argsargument in the mainmethod is already a Stringarray, you can just use args[0].

由于方法中的args参数main已经是一个String数组,您可以使用args[0].

There is no such method String.parseString()btw.

String.parseString()顺便说一句,没有这样的方法。

回答by Tony Meng

args[0]should already be a string if it's coming from command line.

args[0]如果它来自命令行,它应该已经是一个字符串。

If not, use String.valueOf(args[0]).

如果没有,请使用String.valueOf(args[0]).

See http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/String.html

http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/String.html