summaryrefslogtreecommitdiff
path: root/src/com/ensemble/wordcount/LengthComparator.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/com/ensemble/wordcount/LengthComparator.java')
-rw-r--r--src/com/ensemble/wordcount/LengthComparator.java17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/com/ensemble/wordcount/LengthComparator.java b/src/com/ensemble/wordcount/LengthComparator.java
new file mode 100644
index 0000000..9692097
--- /dev/null
+++ b/src/com/ensemble/wordcount/LengthComparator.java
@@ -0,0 +1,17 @@
+package com.ensemble.wordcount;
+
+import java.util.Comparator;
+
+ /**
+ * A Comparator class for comparing the lengths of strings
+ * This is used for sorting the list of words by length
+ *
+ * @author Joe Robinson
+ */
+ public class LengthComparator implements Comparator<String> {
+
+ @Override
+ public int compare(String string1, String string2) {
+ return string2.length() - string1.length();
+ }
+ } \ No newline at end of file