Implementing algorithms in java

When implementing an algorithm in java, should I put it into a class or just leave the code as method(s)?

It’s your choice honestly.

Does anyone else have anything else to say because I asked some people elsewhere and they said use a class but i don’t see how that would be very helpful for something like binary search.

Yeah, as far as I can see a class wouldn’t help for algorithms like binary search. However, it would be helpful to have a class for things such as a tree, where you can implement things such as finding the LCA or a segment tree.

Personally, I like to keep algorithms in classes if I also need to implement a data structure. For example, if I need to implement Dijkstra’s (which means I also need to implement a graph), I will create a separate class for the graph, and code Dijkstra as a method within the graph. For stuff like binary search or DFS, I just leave it as a method. In the end though, it’s just personal preference IMO.