标签:
package study; import static org.junit.Assert.*; import java.util.Arrays; import java.util.Date; import org.junit.Test; public class test { @Test public void test() { System.out.println(Math.sqrt(7.0)); } @Test public void testLong() { Long sum = 0L; long start = System.currentTimeMillis(); for (long i = 0L; i < Integer.MAX_VALUE; i++) { sum += i; } long end = System.currentTimeMillis(); System.out.println("第一次执行耗时" + (end - start)); long sum2 = 0L; long start2 = System.currentTimeMillis(); for (long i = 0L; i < Integer.MAX_VALUE; i++) { sum2 += i; } long end2 = System.currentTimeMillis(); System.out.println("第2次执行耗时" + (end2 - start2)); } @Test public void testMember() { Member m = new Member(); m.setId(12); m.setName("qqqq"); Object m2 = new Object(); // clone(); } @Test public void testExchange() { String a = "aZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZZ"; String b = "bdd"; Exchange.exchangeString(a, b); System.out.println(a); System.out.println(b); } @Test public void testInteger() { Integer a = new Integer(12); Integer b = new Integer(129); Exchange.exchangeInteger(a, b); System.out.println(a); System.out.println(b); } @Test public void testDate() { Date a = new Date(System.currentTimeMillis() - 60 * 60 * 1000 * 7 * 24); Date b = new Date(); Exchange.exchangeDate(a, b); System.out.println(a); System.out.println(b); } @Test public void testExchangeArray() { String[] arr = new String[]{"qq","ww"}; Exchange.exchangeArray(arr); System.out.println(Arrays.toString(arr)); } //经过测试 Integer,String,Date,这些类也用的是值传递 }
package study; import java.util.Date; public class Exchange { public static void exchangeString(String a,String b) { String temp = a; a = b; b = temp; } public static void exchangeInteger(Integer a, Integer b) { Integer temp = a; b = a; a = temp; } public static void exchangeDate(Date a,Date b) { Date temp = a; a = b; b = temp; } public static void exchangeArray(String[] arr) { String temp = arr[0]; arr[0] = arr[1]; arr[1] = temp; } }
测试环境是ubuntukylin 14.04 x64 java1.8
标签:
原文地址:http://www.cnblogs.com/rocky-AGE-24/p/5769931.html