0

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.

4 Answers 4

1

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

Sign up to request clarification or add additional context in comments.

Comments

1

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


 }

Comments

0

How about

"bbccaa".equals(anotherString)

or

"bbccaa".compareTo(anotherString)

See

Comments

0

How is this string generated? If you use Streams you save the stream as a string and use the equals-Method

1 Comment

Why does it matter how the string is generated. The only safe way to compare strings is using equals.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.