-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
- Loading branch information
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
### IntelliJ IDEA ### | ||
out/ | ||
!**/src/main/**/out/ | ||
!**/src/test/**/out/ | ||
|
||
### Eclipse ### | ||
.apt_generated | ||
.classpath | ||
.factorypath | ||
.project | ||
.settings | ||
.springBeans | ||
.sts4-cache | ||
bin/ | ||
!**/src/main/**/bin/ | ||
!**/src/test/**/bin/ | ||
|
||
### NetBeans ### | ||
/nbproject/private/ | ||
/nbbuild/ | ||
/dist/ | ||
/nbdist/ | ||
/.nb-gradle/ | ||
|
||
### VS Code ### | ||
.vscode/ | ||
|
||
### Mac OS ### | ||
.DS_Store |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Large diffs are not rendered by default.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<module type="JAVA_MODULE" version="4"> | ||
<component name="NewModuleRootManager" inherit-compiler-output="true"> | ||
<exclude-output /> | ||
<content url="file://$MODULE_DIR$"> | ||
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" /> | ||
<sourceFolder url="file://$MODULE_DIR$/test" isTestSource="true" /> | ||
</content> | ||
<orderEntry type="inheritedJdk" /> | ||
<orderEntry type="sourceFolder" forTests="false" /> | ||
<orderEntry type="module-library" scope="TEST"> | ||
<library name="JUnit5.8.1"> | ||
<CLASSES> | ||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter/5.8.1/junit-jupiter-5.8.1.jar!/" /> | ||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-api/5.8.1/junit-jupiter-api-5.8.1.jar!/" /> | ||
<root url="jar://$MAVEN_REPOSITORY$/org/opentest4j/opentest4j/1.2.0/opentest4j-1.2.0.jar!/" /> | ||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-commons/1.8.1/junit-platform-commons-1.8.1.jar!/" /> | ||
<root url="jar://$MAVEN_REPOSITORY$/org/apiguardian/apiguardian-api/1.1.2/apiguardian-api-1.1.2.jar!/" /> | ||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-params/5.8.1/junit-jupiter-params-5.8.1.jar!/" /> | ||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/jupiter/junit-jupiter-engine/5.8.1/junit-jupiter-engine-5.8.1.jar!/" /> | ||
<root url="jar://$MAVEN_REPOSITORY$/org/junit/platform/junit-platform-engine/1.8.1/junit-platform-engine-1.8.1.jar!/" /> | ||
</CLASSES> | ||
<JAVADOC /> | ||
<SOURCES /> | ||
</library> | ||
</orderEntry> | ||
<orderEntry type="library" name="KotlinJavaRuntime" level="project" /> | ||
</component> | ||
</module> |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package ch02; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class GenericExample { | ||
public static void main(String[] args) { | ||
List listNames1 = new ArrayList(); | ||
listNames1.add("카리나"); | ||
listNames1.add("윈터"); | ||
listNames1.add("지젤"); | ||
listNames1.add("닝닝"); | ||
String name0 = (String) listNames1.get(0); | ||
|
||
listNames1.add(34); | ||
// String name4 = (String) listNames1.get(4); // 에러 발생 | ||
|
||
// --- | ||
|
||
List<String> listNames2 = new ArrayList<String>(); | ||
listNames2.add("카리나"); | ||
listNames2.add("윈터"); | ||
listNames2.add("지젤"); | ||
listNames2.add("닝닝"); | ||
// listNames2.add(34); // 에러 발생 | ||
|
||
for (String name : listNames2) { | ||
System.out.println(name); | ||
} | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package ch02; | ||
|
||
public class LambdaExpressionExample { | ||
@FunctionalInterface | ||
interface MathInterface { | ||
double getPiValue(); | ||
} | ||
|
||
public static void main(String[] args) { | ||
MathInterface math1 = new MathInterface() { | ||
@Override | ||
public double getPiValue() { | ||
return 3.141592; | ||
} | ||
}; | ||
System.out.println("Pi: " + math1.getPiValue()); | ||
|
||
// --- | ||
|
||
MathInterface math2 = () -> 3.141592; | ||
System.out.println("Pi: " + math2.getPiValue()); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
package ch02; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collections; | ||
import java.util.Comparator; | ||
import java.util.List; | ||
|
||
public class LambdaExpressionSortExample { | ||
static class Member { | ||
String name; | ||
int age; | ||
|
||
public Member(String name, int age) { | ||
this.name = name; | ||
this.age = age; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "Member{" + | ||
"name='" + name + '\'' + | ||
", age=" + age + | ||
'}'; | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
// 리스트에 데이터 삽입 | ||
List<Member> members1 = new ArrayList<>(); | ||
members1.add(new Member("윈터", 23)); | ||
members1.add(new Member("카리나", 24)); | ||
members1.add(new Member("닝닝", 22)); | ||
|
||
// 정렬을 익명 클래스로 구현 | ||
Collections.sort(members1, new Comparator<Member>() { | ||
@Override | ||
public int compare(Member o1, Member o2) { | ||
return o2.age - o1.age; | ||
} | ||
}); | ||
|
||
System.out.println(members1); | ||
|
||
// --- | ||
|
||
List<Member> members2 = new ArrayList<>(); | ||
members2.add(new Member("윈터", 23)); | ||
members2.add(new Member("카리나", 24)); | ||
members2.add(new Member("닝닝", 22)); | ||
|
||
// 정렬을 람다 표현식으로 구현 | ||
members2.sort((o1, o2) -> o2.age - o1.age); | ||
|
||
System.out.println(members2); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
package ch02; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Arrays; | ||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public class SteamAPIExample { | ||
static class Member { | ||
String name; | ||
int age; | ||
|
||
public Member(String name, int age) { | ||
this.name = name; | ||
this.age = age; | ||
} | ||
} | ||
|
||
public static void main(String[] args) { | ||
List<Member> members1 = new ArrayList<>(); | ||
members1.add(new Member("카리나", 24)); | ||
members1.add(new Member("윈터", 23)); | ||
members1.add(new Member("지젤", 24)); | ||
members1.add(new Member("닝닝", 22)); | ||
|
||
// 스트림 API를 사용하지 않은 예전 방식 | ||
List<String> chosenMembers = new ArrayList<>(); | ||
// 나이가 24세인 멤버의 이름을 chosenMembers 리스트에 삽입 | ||
for (Member member : members1) { | ||
if (member.age == 24) | ||
chosenMembers.add(member.name); | ||
} | ||
// chosenMembers 정렬 | ||
Collections.sort(chosenMembers); | ||
// chosenMembers 출력 | ||
for (String name : chosenMembers) { | ||
System.out.println(name); | ||
} | ||
|
||
// --- | ||
|
||
List<Member> members2 = new ArrayList<>(); | ||
members2.add(new Member("카리나", 24)); | ||
members2.add(new Member("윈터", 23)); | ||
members2.add(new Member("지젤", 24)); | ||
members2.add(new Member("닝닝", 22)); | ||
|
||
members2.stream() // 스트림 API | ||
.filter(m -> m.age == 24) // 24세 필터링 | ||
.map(m -> m.name) // 이름 매핑 | ||
.sorted() // 정렬 | ||
.collect(Collectors.toList()) // 리스트로 취합(아래 출력시 생략 가능) | ||
.forEach(System.out::println); // 메소드 참조로 출력 | ||
|
||
// --- | ||
|
||
// 숫자 리스트 | ||
List<Double> numbers1 = Arrays.asList(49.1, 25.5, 9.9); | ||
// 람다 표현식 | ||
numbers1.stream() // 스트림 API | ||
.map(n -> Math.round(n)) // 반올림 처리 | ||
.forEach(n -> System.out.println(n)); // 순회하며 출력 | ||
|
||
// --- | ||
|
||
// 숫자 리스트 | ||
List<Double> numbers2 = Arrays.asList(49.1, 25.5, 9.9); | ||
// 메소드 참조 | ||
numbers2.stream() // 스트림 API | ||
.map(Math::round) // 반올림 처리 | ||
.forEach(System.out::println); // 순회하며 출력 | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
package ch03 | ||
|
||
fun main() { | ||
val arr: Array<Int> = arrayOf(5, 1, 3) | ||
println(arr.max()) | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package ch03; | ||
|
||
public class JavaConditionExample { | ||
public String getTypeOfDayWithSwitchStatement(int dayOfWeek) { | ||
String typeOfDay; | ||
switch (dayOfWeek) { | ||
case 1: | ||
typeOfDay = "한 주의 시작"; | ||
break; | ||
case 2: | ||
case 3: | ||
case 4: | ||
typeOfDay = "주중"; | ||
break; | ||
case 5: | ||
typeOfDay = "한 주의 끝"; | ||
break; | ||
case 6: | ||
case 7: | ||
typeOfDay = "주말"; | ||
break; | ||
default: | ||
throw new IllegalArgumentException("잘못된 날: " + dayOfWeek); | ||
} | ||
return typeOfDay; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package ch03 | ||
|
||
fun getTypeOfDayWithSwitchStatement(dayOfWeek: Int): String { | ||
val typeOfDay: String = when (dayOfWeek) { | ||
1 -> "한 주의 시작" | ||
2, 3, 4 -> "주중" | ||
5 -> "한 주의 끝" | ||
6, 7 -> "주말" | ||
else -> throw IllegalArgumentException("잘못된 날: $dayOfWeek") | ||
} | ||
return typeOfDay | ||
} |