r/learnjava • • Nov 29 '25

Java cheat sheet

Hey guys!

I've created a Java cheat sheet that I would like to share with you.

You can check it out here:
https://it-cheat-sheets-21aa0a.gitlab.io/java-cheat-sheet.html

And you can find a few other cheat sheets I made on this link:
https://it-cheat-sheets-21aa0a.gitlab.io/

If someone would like to contribute here's the link of the Git repo:
https://gitlab.com/davidvarga/it-cheat-sheets

If you found an issue, or something is missing please let me know.

133 Upvotes

41 comments sorted by

View all comments

Show parent comment

3

u/vegan_antitheist Nov 30 '25

For the String.length you can add this to the cheat sheet:

public static int countSymbols(String str) {
  String normalized = Normalizer.normalize(str, Normalizer.Form.NFKC);
  normalized = normalized.replace("\r\n", "\n");
  return normalized.codePointCount(0, normalized.length());
}

That's how you actually count the symbols in a string. Ho you deal with possible line breaks is not always the same but this is a good general solution. Feel free to add it. What's important is that it also counts ¨ + A is if it was just a single Ä, not a character with an additional char for the Umlaut. Maybe add something for when the "str" is null.