Thursday, March 24, 2016

Java 8 - using stream API to add numbers in an array

Integer[] nums = {1,2,3,4,5,6,7};
List<Integer> numbers = Arrays.asList(nums);
int sum = numbers.stream().reduce(0, (x, y) -> x+y);
System.out.println(sum);
sum = numbers.stream().mapToInt(i -> i).sum();
System.out.println(sum);

Wednesday, July 30, 2014

Sublime Text: Compile and Run Java class within Sublime Text in Windows

To compile and run a Java class using a single command Ctrl + B within Sublime Text 2 or Sublime Text 3 beta in Windows based systems, update the Sublime Text file located at "<User Directory>\AppData\Roaming\Sublime Text 2\Packages\Java\Java.sublime-build" with the below script. Create folder/file if you don't have one. Also change Java bin directory to yours.


"cmd": ["javac", "$file_name", "&&", "java", "$file_base_name"], 
"shell": true, 
"path": "C:\\Program Files (x86)\\Java\\jdk1.8.0_05\\bin", 
"file_regex": "^(...*?):([0-9]*):?([0-9]*)", 
"selector": "source.java" 
}

Here's I believe what you are expecting:


















Change your Sublime Text Build System to Java if necessary.




Note: If you are using portable version of Sublime Text, I am guessing you will want to put this under the Sublime Text installation directory e.g "Sublime Text 2\Packages\Java\Java.sublime-build". Again you may have to create any folder/file if it does not exist.