package com.levelup.java.string;

import static org.junit.Assert.assertTrue;

import org.junit.Test;

/**
 * This java example will demonstrate comparing
 * strings.
 * 
 * @author Justin Musgrove
 * @see <a href='http://www.leveluplunch.com/java/'></a>
 * 
 */
public class CompareStrings {
	
	@Test
	public void compare_strings_in_java () {
		
		boolean stringEquals = "test".equals("test");
		
		assertTrue(stringEquals);
	}

	@Test
	public void compare_strings_ignoring_case_in_java () {
		
		boolean stringEquals = "test".equalsIgnoreCase("TEST");
		
		assertTrue(stringEquals);
	}
	
}

@@ -68,14 +68,91 @@
 sert
-True;%0A
+Equals;%0Aimport static org.junit.Assert.assertTrue;%0A%0Aimport org.apache.log4j.Logger;
 %0Aimp
@@ -235,16 +235,75 @@
 strings.
+  Check out http://en.wikipedia.org/wiki/String_intern_pool
 %0A * %0A * 
@@ -423,16 +423,96 @@
 ngs %7B%0A%09%0A
+%09private static final Logger logger = Logger.getLogger(CompareStrings.class);%0A%09%0A
 %09@Test%0A%09
@@ -678,129 +678,1350 @@
 ngs_
-ignoring_case_in_java () %7B%0A%09%09%0A%09%09boolean stringEquals = %22test%22.equalsIgnoreCase(%22TEST%22);%0A%09%09%0A%09%09assertTrue(stringEquals);%0A%09%7D
+compiler_interned_in_java () %7B%0A%0A%09%09String leftString = %22test%22;%0A%09%09String rightString = %22test%22;%0A%09%09%0A%09%09if (leftString == rightString) %7B%0A%09%09%09logger.info(%22yes these are true b/c literals are interned by compiler%22);%0A%09%09%7D%0A%09%09%0A%09%09assertEquals(leftString, rightString);%0A%09%7D%0A%09%0A%09@Test%0A%09public void compare_strings_concatenation_in_java () %7B%0A%09%09%0A%09%09String leftString = %22test%22;%0A%09%09String rightString = %22te%22 + %22st%22;%0A%0A%09%09if (leftString == rightString) %7B%0A%09%09%09logger.info(%22yes these are true b/c concatenation of string literals happens at compile time resulting in same objects%22);%0A%09%09%7D%0A%09%09assertEquals(leftString, rightString);%0A%09%09%0A%09%7D%0A%09%0A%09@Test%0A%09public void compare_strings_ignoring_case_in_java () %7B%0A%09%09%0A%09%09boolean stringEquals = %22test%22.equalsIgnoreCase(%22TEST%22);%0A%09%09%0A%09%09assertTrue(stringEquals);%0A%09%7D%0A%09%0A%09@Test%0A%09public void compare_strings_with_nulls_in_java () %7B%0A%09%09String leftString = null;%0A%09%09String rightString = null;%0A%09%09%0A%09%09if (leftString == rightString) %7B%0A%09%09%09logger.info(%22yes%22);%0A%09%09%7D%0A%09%09%0A%09%09assertEquals(leftString, rightString);%0A%09%09%0A%09%7D%0A%0A%09@SuppressWarnings(%22null%22)%0A%09@Test(expected=NullPointerException.class)%0A%09public void compare_strings_with_nulls_with_exception_in_java () %7B%0A%09%09String leftString = null;%0A%09%09String rightString = null;%0A%09%09%0A%09%09logger.info(%22strings are objects so if access a method on a null object, null pointer exception%22);%0A%09%09%0A%09%09leftString.equals(rightString);%0A%09%7D%0A%09%0A%09
 %0A%09%0A%7D

add compare strings