Learn to create clone of an array in Java with example. Clone creates shallow copy of an array. Also learn to create array deep copies. Array Clone – Shallow Copy In Java, to create clone of array, you should use clone() method of array. It creates a shallow copy of array. Cloning always creates shallow […]
Learn to create deep copy of an array in Java with example. We will be using Apache Commons Lang library and it’s utility class org.apache.commons.lang3.SerializationUtils to array deep copy. Array Deep Copy Example A deep copy of an array will have all objects and it’s referred objects – created fresh. References from old array will […]
Java example to convert string into string array using String.split() method and using java.util.regex.Pattern class. Quick Reference: 1) Convert String to String 1.1) String.split() Use split() method to split string into tokens by passing a delimiter (or regex) as method argument. 1.2) Pattern.split() In Java, Pattern is the compiled representation of a regular expression. Use […]
Java example to print 2d array in string format in console or server logs.
Java example to create subarray from array. Learn to use Java 8 Arrays.copyOfRange() method along with converting the subarray to list object.
Java examples to copy an array to another array object using array clone, System.arrayCopy() and Arrays.copyOf() methods.
Learn to convert byte to String and String to byte in java – with examples. Conversion between byte array and string may be used in many cases including IO operations, generate secure hashes etc.
While working with encryption algorithms, you may get encrypted text as byte, which later need to be converted to String for comparison purpose. Converting byte to String in java is pretty much straightforward and easy. You need to use String class constructor String(byte bytes) or String(byte bytes, String charsetName) and you will get String represenation […]
Java examples to learn about JDK’s existing support to print array content in more informative way, than normal toString() method which does not provide much information. 1) Arrays.toString() – Print array content Recommended way to print the content of an array is using Arrays.toString(). 2) Arrays.deepToString() – Print array of arrays What will happen if […]