Skip to main content

Posts

Java: Convert between int or Integer arrays to List with Java 8 features

#1 how to convert int[]/ Integer[] to list for int[]: int[] arr = {1, 2, 3}; //you have to box the primitive type of Integer List<Integer> list = Arrays.stream(arr).boxed().collect(Collectors.toList()); for Integer: Integer[] arr = {1, 2, 3}; List<Integer> list = Array.asList(array); but cannot do: list.remove(0); // UnsupportedOperationException :( Here you cannot remove the 0 element because asList returns a fixed-size list backed by the specified array. So you should do something like: List<Object> newList = new ArrayList<>(Arrays.asList(array)); in order to make the newList modifiable. #2 how to convert Integer[] to list, and  to int[] Integer[] arr = {1, 2, 3}; //to list List<Integer> list = Array.asList(array); // to int[] int[] array = list.stream().mapToInt(x->x).toArray(); //to back to Integer[] Integer[] array = list.stream().mapToInt(x->x).boxed().toArray(Integer[]::new); more examples: Integer[] a = {1,...

Spring Data Rest Vs Spring Data JPA vs Hibernate

Spring Data JPA wrapped the implementation from the vendor(default Hibernate); Spring Data Rest will support features including convert the data service into HAL(hypertext Application language) based on rest service. Like Spring Data Elasticsearch and others, Spring Data JPA is one of the data service(for relational database) supported by Spring Data Rest

System.arraycopy() vs. Arrays.copyOf() in Java

source: https://www.programcreek.com/2015/03/system-arraycopy-vs-arrays-copyof-in-java/ System.arraycopy() vs. Arrays.copyOf() in Java   If we want to copy an array, we can use either  System.arraycopy()  or  Arrays.copyOf() . In this post, I use a simple example to demonstrate the difference between the two. 1. Simple Code Examples System.arraycopy() int [ ] arr = { 1 , 2 , 3 , 4 , 5 } ;   int [ ] copied = new int [ 10 ] ; System . arraycopy ( arr, 0 , copied, 1 , 5 ) ; //5 is the length to copy   System . out . println ( Arrays . toString ( copied ) ) ; Output: [0, 0, 0, 0, 0, 0, 0, 0, 0, 0] [0, 1, 2, 3, 4, 5, 0, 0, 0, 0] Arrays.copyOf() int [ ] copied = Arrays . copyOf ( arr, 10 ) ; //10 the the length of the new array System . out . println ( Arrays . toString ( copied ) ) ;   copied = Arrays . copyOf ( arr, 3 ) ; System . out . println ( Arrays . toString ( copied ) ) ; Output: [1, 2, 3, 4, 5, ...

Sublime 3 - useful keyboard shortcuts

source #1: http://www.hongkiat.com/blog/sublime-text-tips/ source #2: https://www.cheatography.com/tdeyle/cheat-sheets/sublime-text-3/ Ctrl + D Select a word. Ctrl + L Select a line. Ctrl + A Select the entire content within the document. Ctrl + Shift + M Select anything inside the bracket (which is useful when working with CSS or JavaScript) Furthermore, Sublime Text brings lets us select multiple lines at once, which can significantly boost your productivity. There are several ways to perform this feature: Ctrl Hold the Ctrl key and click on the lines that you want to select. Ctrl + Shift + G Select a code, line, or word first the hit this combo to select the others with the same instances. Ctrl + D Hit this key to quickly select the next code, line, or word that has the same instances as you are currently selecting.

Spring boot Common application properties

http://docs.spring.io/spring-boot/docs/current/reference/html/common-application-properties.html # =================================================================== # COMMON SPRING BOOT PROPERTIES # # This sample file is provided as a guideline. Do NOT copy it in its # entirety to your own application. ^^^ # =================================================================== # ---------------------------------------- # CORE PROPERTIES # ---------------------------------------- # BANNER banner.charset =UTF-8 # Banner file encoding. banner.location =classpath:banner.txt # Banner file location. banner.image.location =classpath:banner.gif # Banner image file location (jpg/png can also be used). banner.image.width = # Width of the banner image in chars (default 76) banner.image.height = # Height of the banner image in chars (default based on image height) banner.image.margin = # Left hand image margin in chars (default 2) banner.image.invert = # If images...