Remove all redundant empty lines, be careful :)
If you create a formatter, make it a constant field.
If you create a formatter, make it a constant. That will make your code easier to understand. Plus if you use it in several places in your code you will be able to change its value easily with one action(change variable declaration). In other case you need to update value in each place it's being used.
Here is some background why you should use it primarily.
The more loops you have, the slower your code may get, so try to solve task with minimum amount.
They may simplify the work for you, but for now you will get more value from solving this task if you complete it without using these data structures. Let's do it manually.
You have learned in previous topics about different internal structure of String
and StringBuilder
don't forget to use it
on practice. Keep in mind that String concatenation creates many new objects that take up a lot of memory if you use it inside
of a loop. Though it's safe to use it outside of a loop, because compiler will replace it with StringBuilder anyway java doc
Different OS handle line separators differently. Instead of using \n
or \r\n
use universal solution - System.lineSeparator()
.
Do not use abstract words like string
or array
as variable name. Do not use one-letter names. The name of the method should make it clear what it does.
- Bad example:
String[] arr = new String[]{"Alex", "Bob", "Alice"}; for (String s : arr) { System.out.println(s); }
- Refactored code:
String[] usernames = new String[]{"Alex", "Bob", "Alice"}; for (String username : usernames) { System.out.println(username); }
Your code should be easy to read. Move all hardcoded values to constant fields and give them informative names.
Bad example of commit/PR message: done
/fixed
/commit
/solution
/added homework
/my solution
and other one-word, abstract or random messages.