Last active
April 17, 2016 14:18
-
-
Save avence12/15fcdad1d371e2422b2a5d418784c35c to your computer and use it in GitHub Desktop.
Code of Java Interview Question - http://www.lightblue.asia/java-interview-questions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Example 1: new Runnable | |
Runnable run = new Runnable() { | |
public void run() { | |
System.out.println("run me!"); | |
} | |
}; | |
// one line lambda | |
Runnable run = () -> System.out.println("run me!"); | |
// Exmaple 2: Iterate Map | |
Set keySet = map.keySet(); | |
for (String s : keySet) { | |
System.out.print(s + ":" + map.get(s)); | |
} | |
// one line lambda | |
map.forEach((k, v) -> System.out.print(k + ":" + v)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
List list = new ArrayList(); | |
list.add("1"); | |
list.add("2"); | |
list.add("3"); | |
list.add("5"); | |
list.add("4"); | |
list.stream().filter(s -> Integer.valueOf(s) < 3).forEach(s -> System.out.print(s)); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class MySingleton{ | |
private static MySingleton uniqueInstance; | |
private MySingleton(){} // 使用Private以確保mySingleton 只能透過 API:getInstance() 產生Instance | |
public static synchronized MySingleton getInstance() { | |
if(uniqueInstance == null ) {uniqueInstance = new mySingleton();} | |
return uniqueInstance; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
abc |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment