[Java] Tools package | Sololearn: Learn to code for FREE!

+7

[Java] Tools package

Hi ! I'm a java beginner. I was wondering if it was a good idea to create a Tools Package. for example I could create a method say instead of System.out.println (). A method too to display the contents of an Array ... so I could import this toolbox into each of my projects. Thank you in advance for your opinions and good codes to all!

6/9/2018 6:28:49 AM

Frédéric PARENT

3 Answers

New Answer

+8

Depends on the scale of your project and the benefit modularization would bring you. For printing arrays, two lines of: for (ArrayType i : yourArray) System.out.print(i + " "); doesn't seem like too much hassle to re-type each time you need it. However, I can totally see why you would need one when you want a method to handle generic datatypes, or when you have to print the array in a formatted way, e.g. in a table, with proper labels, units. Just make sure that modularizing stuff will actually save your time instead of adding complexity to your project.

+2

Hi Frédéric PARENT Yes, it's a very good idea always to create a tools(also called util, short for utility) package. I usually like to have a util package for every project I'm working on, where I put my parsers, date functionalities, etc.

+1

I tried that method of printing. Due to my limited knowledge, I had to create the method multiple times to account for printing strings, integers, doubles, arrays etc. I'm sure there is a better way to be able to pass any data type into a function without making multiple datatypes for each, but that's just a limitation to my toolbox.