String str1 = "hello"; String str2 = new String("hello"); assertNotSame(str1, str2);
ListIn this example, we create two List objects using the Arrays.asList() method. While the two lists have the same elements, they reference different instances. The assertNotSame() method passes because the two lists are not the same instance. The org.junit.Assert.assertNotSame() method is part of the JUnit testing framework, which is typically included as a package library in Java projects.list1 = Arrays.asList("apple", "banana"); List list2 = Arrays.asList("apple", "banana"); assertNotSame(list1, list2);