Skip to content

Tag: java

Compare two objects excluding some fields – Java

I need to compare two objects of the same class excluding some fields. How can i find if the two objects of the above class are equal excluding createdAt and updatedAt values? Since there are a lot of fields in this class, i don’t want to compare each of them one by one. Please don’t give AssertJ&…

Reducing ArrayList using MyClass attributes

I have a class, MyClass, like this: If I want to get the sum of amount in an ArrayList of MyClass items, usually I would do this: But now to improve performance, I am trying to use Stream.reduce(). My approach: Is there a better way to do so? And how would the reduction be affected if currAmount or nextAmount…

Java rock-paper-scissors program does not print right output

I want my program to display what the computer chose. But instead, it sometimes does not, or sometimes it does display The computer chose Rock The computer chose Paper The computer chose Scissors This happens even if i follow the same input pattern. Output when the user inputs 1 , 2 , 3 in order- Similarly, o…

Java – Check if user input partialy matches another string?

I have a problem where i want to see if the input user has enterd partially matches, or as long as majority matches with the answer, if it does then it should print out “Almost correct”. For example lets say the answer is Football, but user instead puts in Footbol. It should then print out Almost …