I have written a program that gives an output like
"bbccaa"
Is there a way in java to store this into a sting and compare to another string.
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 ....
String s = "hello";
String sOutput = "bbccaa";
if (sOutput.equalsIgnoreCase(s)){ // Ignore case while comparing
}
if (sOutput.equals(s)){ // Consider case while comparing
}
How is this string generated? If you use Streams you save the stream as a string and use the equals-Method
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.