LeetCode – Longest Common Prefix (Java)

Problem Write a function to find the longest common prefix string amongst an array of strings. Analysis To solve this problem, we need to find the two loop conditions. One is the length of the shortest string. The other is iteration over every element of the string array. Java Solution public String longestCommonPrefix(String[] strs) { … Read more

Spring MVC Tutorial: Process Form Submission

Spring Tutorial Index Page Previous – Dependency Injection Next – Form Validation This article shows how to process form in Spring. In this program, a form submission module will be added. Specifically, we will use web form to add a new employee and show the new employee list. Step 1: Prepare Required Classes Add addEmployee … Read more

Spring MVC Tutorial – Setter Dependency Injection

Spring Tutorial Index Page Previous: Hello World Next: Handling Form Submission In previous tutorial, we have seen how to create a simple Hello World Spring application using Maven under Eclipse. In the Hello World application, we used annotation. In this tutorial, I will show how to use xml configuration and setter dependency injection. Instead of … Read more

K-Means Clustering in Java

This post shows how to run k-means clustering algorithm in Java using Weka. First, download weka.jar file here. When it is unzipped, you have files like this: Add the weka.jar file to your project build path, and then take a look at the .arff file under data directory. By reading one or two of them, … Read more

Spring MVC HelloWorld Using Maven in Eclipse

Java developers often rely on examples to learn Spring framework. Simple examples are often a key learning resource. There are many Spring MVC HelloWorld applications. However, most of them are outdated (do not integrate Maven, use old version of Spring, etc) or not complete (missing key steps or file hierarchy view). Therefore can not lead … Read more

LeetCode – Reverse Words in a String (Java)

Given an input string, reverse the string word by word. For example, given s = “the sky is blue”, return “blue is sky the”. Java Solution This problem is pretty straightforward. We first split the string to words array, and then iterate through the array and add each element to a new string. Note: StringBuilder … Read more