What can replace instanceof for java 11?

@Override public int compareTo(@NotNull Object o) { if (o instanceof Task task) { if (task.getStartTime() == null) { return -1; } else if (task.getStartTime().isBefore(this.startTime)) { return 1; } else if (task.getStartTime().isAfter(this.startTime)) { return -1; } else return 0; } else throw new RuntimeException("Не наследник Task"); } java: pattern matching in instanceof is not supported in… Read More What can replace instanceof for java 11?

Can Collections.sort() take treeSet as first argument? If not why?

I have my ‘Person’ class as follows – public class Person implements Comparable<Person> { private int marks; private String name; Person(int marks, String name) { this.marks = marks; this.name = name; } public int getMarks() { return marks; } public String getName() { return name; } @Override public String toString() { return "Person: Marks =… Read More Can Collections.sort() take treeSet as first argument? If not why?

How to update a specific value in List<Class>?

I need to update one data in my List<Cards>. Class Cards looks like this: public class Cards implements Comparable<Cards>{ private int cardImage, cardID, cardScore; public Cards(int cardImage, int cardID, int cardScore){ this.cardImage = cardImage; this.cardID = cardID; this.cardScore = cardScore; } public int getImage(){ return cardImage; } public int getId(){ return cardID; } public int… Read More How to update a specific value in List<Class>?

Sorting an array based on different properties of objects by overriding compareTo() method

I have a list of Student objects, each of them has 3 properties. Color, Size and their names. I want to sort them in ascending order based on their color first, followed by descending order of size and finally, in ascending order of their names. For example, if input is (first line name, second line… Read More Sorting an array based on different properties of objects by overriding compareTo() method

Trying to compare two words in alphabetical order using a while loop to see which one if guess comes before of after word

I am trying to compare two words and see if guess comes before word using compareTo() while(!guess.equals(word)){ if(compare < 0){ System.out.println(word + " Comes before your guess. "); detail(); } else if(compare > 0) { System.out.println(word + "Comes after your guess. "); detail(); } } System.out.println("You guessed it!"); >Solution : s1.compareTo(s2) is positive(>0) if s1… Read More Trying to compare two words in alphabetical order using a while loop to see which one if guess comes before of after word