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<String> list = new ArrayList<>(); | |
list.add("First String"); | |
list.add(6); // Compile error | |
String str = list.get(0); // no cast needed |
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
String str = (String)list.get(1); // needs explicit cast, throws exception |
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
fun <T> printType(classType: Class<T>) { | |
print(classType::class.java) | |
} |
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
<!-- Copyright 2019 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
android { | |
defaultConfig { | |
//Only required when setting minSdkVersion to 20 or lower | |
multiDexEnabled true | |
} | |
compileOptions { |
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
// Current date | |
LocalDate date = LocalDate.now(); | |
// Current time | |
LocalTime time = LocalTime.now(); | |
// Date of Android 11 beta launch | |
LocalDate date2 = LocalDate.of(2020, 6, 10); //yyyy,MM,dd |
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
<!-- Copyright 2019 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 → | |
ZonedDateTime currentDate = ZonedDateTime.now(); | |
System.out.println("the current zone is "+ currentDate.getZone()); | |
//the current zone is America/Los_Angeles | |
ZoneId anotherZone = ZoneId.of(“Europe/Istanbul”); | |
ZonedDateTime currentDateInIstanbul = currentZone.withZoneSameInstant(anotherZone); | |
//2020-06-08T23:50:00.159+03:00[Europe/Istanbul] |
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
<!-- Copyright 2019 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
ZoneOffset zoneOffSet= ZoneOffset.of("+03:00"); | |
OffsetDateTime offsetDateTime = OffsetDateTime.now(zoneOffSet); | |
System.out.println(offsetDateTime); | |
//2020-06-08T23:50:17.315+03:00 |
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
<!-- Copyright 2019 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 → | |
LocalDate now = LocalDate.now(); | |
LocalDate androidBeta = LocalDate.of(2020, 6, 10); | |
Period period = Period.between(androidBeta, now); |
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
<!-- Copyright 2019 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
List<person> list = Arrays.asList(personArray); | |
Stream<Person> stream1 = list.stream(); | |
//or | |
Stream<Person> stream2 = Stream.of(personArray); | |
//or |
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
<!-- Copyright 2019 Google LLC. | |
SPDX-License-Identifier: Apache-2.0 --> | |
import static java.util.Comparator.comparing; | |
comparing(Person::getFirstname).thenComparing(Person::getSurname); |