NivG NivG - 27 days ago 8
Java Question

Extract static methods from main() file in java

I'm quite new to Java and wrote a little to-do list project.
At the beginning of the project I added a bunch of static methods to the file where my main() code is, and it got a little out of hand. I want to transfer these methods to another file.
Is there a proper way to do this, or do I just have to create some sort of Behaviour class for these methods, and then in main() create an instance of it to call it's methods?

Answer Source

You can extract these methods to a separate class (say FooUtils), and then in your main method you can call them using the class name - FooUtils.someStaticMethod()

Depending on what you have, it may make sense to group your methods into different classes, or to make them instance methods.