Skip to content

Tag: java

Mirroring an Image in Java

Background info: I’ve made a program that uploads an image using JFileChooser and fills in the space of the JFrame. I then apply filters via buttons. Currently 3 of my 4 filters work, or all except my mirror one. It randomly (or I guess not so randomly as there’s always a reason, I just don’…

Can’t pass wildcard Comparator to function

I have the following sort method in a clone of ArrayList: The sorter object is an instance of Sort: I get the following error on the sorter.mergeSort line: I’m not sure why this is happening as both the parameter and argument have type Comparator<? super E>. Answer Thanks to everyone for their com…

Kth smallest number algorithm doing extra work?

So I’m preparing for a technical interview, and one of my practice questions is the Kth smallest number. I know that I can do a sort for O(n * log(n)) time and use a heap for O(n * log(k)). However I also know I can partition it (similar to quicksort) for an average case of O(n). The actual calculated a…

Java object access for same overall implementation

Perhaps the title of question isnt well created, but i couldnt understand what else I could put in there. I wanted to understand, why the first one out of the two below cases works, and how can I get the second one to work as well, given the overall implementation is same. From a code point of view, what prin…