简体   繁体   English

如何将输出与java中的字符串进行比较?

[英]How do I compare the output with a string in java?

I have written a program that gives an output like 我写了一个程序,给出了类似的输出

"bbccaa" “bbccaa”

Is there a way in java to store this into a sting and compare to another string. 在java中是否有一种方法可以将其存储到sting中并与另一个字符串进行比较。

What do you mean by 'gives an output' ? “给出输出”是什么意思? Does it print the string to the console? 它是否将字符串打印到控制台?

Assuming that you have something like: 假设你有类似的东西:

String s = ...; // Something that creates bbccaa
System.out.println(s);

Then you can just do: 然后你可以这样做:

s.equals(otherString);

to compare the two strings 比较两个字符串

Use equalsIgnoreCase() or equals() to compare 2 String objects .... 使用equalsIgnoreCase()equals()比较2个String对象 ....

String s = "hello";

String sOutput = "bbccaa";

if (sOutput.equalsIgnoreCase(s)){   // Ignore case while comparing


 }


if (sOutput.equals(s)){            // Consider case while comparing


 }

How about 怎么样

"bbccaa".equals(anotherString)

or 要么

"bbccaa".compareTo(anotherString)

See 看到

How is this string generated? 这个字符串是如何生成的? If you use Streams you save the stream as a string and use the equals-Method 如果使用Streams,则将流保存为字符串并使用equals-Method

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM