diff --git a/core-java-modules/core-java-string-operations-3/pom.xml b/core-java-modules/core-java-string-operations-3/pom.xml
new file mode 100644
index 0000000000..5edff0e090
--- /dev/null
+++ b/core-java-modules/core-java-string-operations-3/pom.xml
@@ -0,0 +1,61 @@
+
+
+ 4.0.0
+ core-java-string-operations-3
+ 0.1.0-SNAPSHOT
+ core-java-string-operations-3
+ jar
+
+ com.baeldung.core-java-modules
+ core-java-modules
+ 0.0.1-SNAPSHOT
+ ../
+
+
+
+
+ org.assertj
+ assertj-core
+ ${assertj.version}
+ test
+
+
+ org.apache.maven
+ maven-artifact
+ ${maven-artifact.version}
+
+
+ org.gradle
+ gradle-core
+ ${gradle-core.version}
+
+
+ com.fasterxml.jackson.core
+ jackson-core
+ ${jackson-core.version}
+
+
+ com.vdurmont
+ semver4j
+ ${semver4j.version}
+
+
+
+
+ 3.6.1
+ 3.6.3
+ 6.1.1
+ 2.11.1
+ 3.1.0
+
+
+
+
+ gradle-repo
+ https://repo.gradle.org/gradle/libs-releases-local/
+
+
+
diff --git a/core-java-modules/core-java-string-operations-3/src/main/java/com/baeldung/versioncomparison/VersionCompare.java b/core-java-modules/core-java-string-operations-3/src/main/java/com/baeldung/versioncomparison/VersionCompare.java
new file mode 100644
index 0000000000..5a1663e50d
--- /dev/null
+++ b/core-java-modules/core-java-string-operations-3/src/main/java/com/baeldung/versioncomparison/VersionCompare.java
@@ -0,0 +1,25 @@
+package com.baeldung.versioncomparison;
+
+public class VersionCompare {
+
+ public static int compareVersions(String version1, String version2) {
+ int comparisonResult = 0;
+
+ String[] version1Splits = version1.split("\\.");
+ String[] version2Splits = version2.split("\\.");
+
+ int maxLengthOfVersionSplits = Math.max(version1Splits.length, version2Splits.length);
+ for (int i = 0; i < maxLengthOfVersionSplits; i++){
+ Integer v1 = i < version1Splits.length ? Integer.parseInt(version1Splits[i]) : 0;
+ Integer v2 = i < version2Splits.length ? Integer.parseInt(version2Splits[i]) : 0;
+ int compare = v1.compareTo(v2);
+ if (compare != 0) {
+ comparisonResult = compare;
+ break;
+ }
+ }
+
+ return comparisonResult;
+ }
+
+}
diff --git a/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/versioncomparison/VersionComparisonUnitTest.java b/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/versioncomparison/VersionComparisonUnitTest.java
new file mode 100644
index 0000000000..145e9788e4
--- /dev/null
+++ b/core-java-modules/core-java-string-operations-3/src/test/java/com/baeldung/versioncomparison/VersionComparisonUnitTest.java
@@ -0,0 +1,136 @@
+package com.baeldung.versioncomparison;
+
+import org.junit.Test;
+
+import com.fasterxml.jackson.core.Version;
+import com.vdurmont.semver4j.Semver;
+import com.vdurmont.semver4j.Semver.VersionDiff;
+
+import org.apache.maven.artifact.versioning.ComparableVersion;
+import org.gradle.util.VersionNumber;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+public class VersionComparisonUnitTest {
+
+ @Test
+ public void givenVersionStrings_whenUsingMavenArtifact_thenCompareVersions() {
+ ComparableVersion version1_1 = new ComparableVersion("1.1");
+ ComparableVersion version1_2 = new ComparableVersion("1.2");
+ ComparableVersion version1_3 = new ComparableVersion("1.3");
+
+ assertTrue(version1_1.compareTo(version1_2) < 0);
+ assertTrue(version1_3.compareTo(version1_2) > 0);
+
+ ComparableVersion version1_1_0 = new ComparableVersion("1.1.0");
+ assertEquals(0, version1_1.compareTo(version1_1_0));
+
+ ComparableVersion version1_1_alpha = new ComparableVersion("1.1-alpha");
+ assertTrue(version1_1.compareTo(version1_1_alpha) > 0);
+
+ ComparableVersion version1_1_beta = new ComparableVersion("1.1-beta");
+ ComparableVersion version1_1_milestone = new ComparableVersion("1.1-milestone");
+ ComparableVersion version1_1_rc = new ComparableVersion("1.1-rc");
+ ComparableVersion version1_1_snapshot = new ComparableVersion("1.1-snapshot");
+
+ assertTrue(version1_1_alpha.compareTo(version1_1_beta) < 0);
+ assertTrue(version1_1_beta.compareTo(version1_1_milestone) < 0);
+ assertTrue(version1_1_rc.compareTo(version1_1_snapshot) < 0);
+ assertTrue(version1_1_snapshot.compareTo(version1_1) < 0);
+
+ ComparableVersion version1_1_c = new ComparableVersion("1.1-c");
+ ComparableVersion version1_1_z = new ComparableVersion("1.1-z");
+ ComparableVersion version1_1_1 = new ComparableVersion("1.1.1");
+
+ assertTrue(version1_1_c.compareTo(version1_1_z) < 0);
+ assertTrue(version1_1_z.compareTo(version1_1_1) < 0);
+ }
+
+ @Test
+ public void givenVersionStrings_whenUsingGradle_thenCompareVersions() {
+ VersionNumber version1_1 = VersionNumber.parse("1.1");
+ VersionNumber version1_2 = VersionNumber.parse("1.2");
+ VersionNumber version1_3 = VersionNumber.parse("1.3");
+
+ assertTrue(version1_1.compareTo(version1_2) < 0);
+ assertTrue(version1_3.compareTo(version1_2) > 0);
+
+ VersionNumber version1_1_0 = VersionNumber.parse("1.1.0");
+ assertEquals(0, version1_1.compareTo(version1_1_0));
+
+ VersionNumber version1_1_1_1_alpha = VersionNumber.parse("1.1.1.1-alpha");
+ assertTrue(version1_1.compareTo(version1_1_1_1_alpha) < 0);
+
+ VersionNumber version1_1_beta = VersionNumber.parse("1.1.0.0-beta");
+ assertTrue(version1_1_beta.compareTo(version1_1_1_1_alpha) < 0);
+
+ VersionNumber version1_1_1_snapshot = VersionNumber.parse("1.1.1-snapshot");
+ assertTrue(version1_1_1_1_alpha.compareTo(version1_1_1_snapshot) < 0);
+ }
+
+ @Test
+ public void givenVersionStrings_whenUsingJackson_thenCompareVersions() {
+ Version version1_1 = new Version(1, 1, 0, null, null, null);
+ Version version1_2 = new Version(1, 2, 0, null, null, null);
+ Version version1_3 = new Version(1, 3, 0, null, null, null);
+
+ assertTrue(version1_1.compareTo(version1_2) < 0);
+ assertTrue(version1_3.compareTo(version1_2) > 0);
+
+ Version version1_1_1 = new Version(1, 1, 1, null, null, null);
+ assertTrue(version1_1.compareTo(version1_1_1) < 0);
+
+ Version version1_1_maven = new Version(1, 1, 0, null, "org.apache.maven", null);
+ Version version1_1_gradle = new Version(1, 1, 0, null, "org.gradle", null);
+ assertTrue(version1_1_maven.compareTo(version1_1_gradle) < 0);
+
+ Version version1_1_snapshot = new Version(1, 1, 0, "snapshot", null, null);
+ assertEquals(0, version1_1.compareTo(version1_1_snapshot));
+
+ assertTrue(version1_1_snapshot.isSnapshot());
+ }
+
+ @Test
+ public void givenVersionStrings_whenUsingSemver_thenCompareVersions() {
+ Semver version1_1 = new Semver("1.1.0");
+ Semver version1_2 = new Semver("1.2.0");
+ Semver version1_3 = new Semver("1.3.0");
+
+ assertTrue(version1_1.compareTo(version1_2) < 0);
+ assertTrue(version1_3.compareTo(version1_2) > 0);
+
+ Semver version1_1_alpha = new Semver("1.1.0-alpha");
+ assertTrue(version1_1.isGreaterThan(version1_1_alpha));
+
+ Semver version1_1_beta = new Semver("1.1.0-beta");
+ Semver version1_1_milestone = new Semver("1.1.0-milestone");
+ Semver version1_1_rc = new Semver("1.1.0-rc");
+ Semver version1_1_snapshot = new Semver("1.1.0-snapshot");
+
+ assertTrue(version1_1_alpha.isLowerThan(version1_1_beta));
+ assertTrue(version1_1_beta.compareTo(version1_1_milestone) < 0);
+ assertTrue(version1_1_rc.compareTo(version1_1_snapshot) < 0);
+ assertTrue(version1_1_snapshot.compareTo(version1_1) < 0);
+
+ assertTrue(version1_1.isEqualTo("1.1.0"));
+
+ assertEquals(VersionDiff.MAJOR, version1_1.diff("2.1.0"));
+ assertEquals(VersionDiff.MINOR, version1_1.diff("1.2.3"));
+ assertEquals(VersionDiff.PATCH, version1_1.diff("1.1.1"));
+
+ assertTrue(version1_1.isStable());
+ assertFalse(version1_1_alpha.isStable());
+ }
+
+ @Test
+ public void givenVersionStrings_whenUsingCustomVersionCompare_thenCompareVersions() {
+ assertTrue(VersionCompare.compareVersions("1.0.1", "1.1.2") < 0);
+ assertTrue(VersionCompare.compareVersions("1.0.1", "1.10") < 0);
+ assertTrue(VersionCompare.compareVersions("1.1.2", "1.0.1") > 0);
+ assertTrue(VersionCompare.compareVersions("1.1.2", "1.2") < 0);
+ assertEquals(0, VersionCompare.compareVersions("1.3.0", "1.3"));
+ }
+
+}
diff --git a/core-java-modules/pom.xml b/core-java-modules/pom.xml
index 34d6bf58a4..03b15f60d6 100644
--- a/core-java-modules/pom.xml
+++ b/core-java-modules/pom.xml
@@ -126,6 +126,7 @@
core-java-string-conversions-2
core-java-string-operations
core-java-string-operations-2
+ core-java-string-operations-3
core-java-strings
core-java-sun