Java Escape HTML – Encode Special Characters
Java examples to escape HTML using the StringEscapeUtils.escapeHtml4(), Spring’s HtmlUtils.htmlEscape() and custom logic for special cases.
Java examples to escape HTML using the StringEscapeUtils.escapeHtml4(), Spring’s HtmlUtils.htmlEscape() and custom logic for special cases.
Till Java 8, String in java were internally represented by char[]. Each char is stored in 2 bytes in memory. JDK developers at oracle analyzed lots of client’s application help dumps and they noticed that most of the strings can be represented only using Latin-1 characters set. A latin-1 char can be stored in one byte, which is 50% (1 byte) less than char data type storage.
learned to parse a string (decimal, octal and hexadecimal) to int or Integer types using Integer.parseInt(), valueOf() and decode() methods.
Learn to split string by comma or space and store in array or arraylist. Use given Java program to convert string to List in Java.
Learn to join string array with delimiter to produce single string. Use listed java example to convert list of strings or array of strings to single string.
Learn to align a string to left, right or center in Java using the utility StringAlignUtils, which wraps all the alignment logic inside it.
Learn to split a String with delimiters in Java using String.split(), StringUtils.split() and Splitter.split() APIs with examples.
Since Java 8, we can use String.join() method to concatenate strings with a specified delimiter. For advanced usages, use StringJoiner class.
The immutable strings help in achieving the required data safety and performance in a Java application with help of underlying string pool.
Learn to find duplicate words in string or sentence along with their counts, using the Collections and Java 8 Stream with Examples.
HowToDoInJava provides tutorials and how-to guides on Java and related technologies.
It also shares the best practices, algorithms & solutions and frequently asked interview questions.