Speed of if compared to conditional
问题 I had the idea I would turn some of my if blocks into single lines, using the conditional operator. However, I was wondering if there would be a speed discrepancy. I ran the following test: static long startTime; static long elapsedTime; static String s; public static void main(String[] args) { startTime = System.nanoTime(); s = ""; for (int i= 0; i < 1000000000; i++) { if (s.equals("")) { s = ""; } } elapsedTime = System.nanoTime() - startTime; System.out.println("Type 1 took this long: " +