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 cases, you need to update the 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 structures of String
and StringBuilder
don't forget to use them in 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 the 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 names. 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 examples of commit/PR messages: done
/fixed
/commit
/solution
/added homework
/my solution
and other one-word, abstract or random messages.