strings-io-and-other-bits-and-pieces-slides
strings-io-and-other-bits-and-pieces-slides
▪
▪
▪
▪
▪
▪
▪
▪
▪
▪
▪
▪
▪
▪
String s1 = "Hello";
String s2 = "world";
String s1 = "Hello";
String s2 = "world";
▪
▪
▪
▪
▪
▪
▪
▪
> {}
▪
> {one}
▪
▪
▪
▪
▪
▪
▪
▪
▪
strings.forEach(System.out::println);
▪
// removes an element on a predicate
Collection<String> strings =
Arrays.asList("one", "two", "three", "four");
System.out.println(
list.stream().collect(Collectors.joining(", ")));
▪
// removes an element on a predicate
Collection<String> strings =
Arrays.asList("one", "two", "three", "four");
System.out.println(
list.stream().collect(Collectors.joining(", ")));
System.out.println(
list.stream().collect(Collectors.joining(", ")));
▪
// removes an element on a predicate
List<String> strings =
Arrays.asList("one", "two", "three", "four");
System.out.println(
list.stream().collect(Collectors.joining(", ")));
System.out.println(
list.stream().collect(Collectors.joining(", ")));
▪
// removes an element on a predicate
List<String> strings =
Arrays.asList("one", "two", "three", "four");
System.out.println(
list.stream().collect(Collectors.joining(", ")));
@Override
public int compare(Person p1, Person p2) {
return p1.getLastName().compareTo(p2.getLastName());
}
};
▪
// comparison using the last name
Comparator<Person> compareLastName =
new Comparator<Person>() {
@Override
public int compare(Person p1, Person p2) {
return p1.getLastName().compareTo(p2.getLastName());
}
};
▪
▪
// comparison using the last name then the first name
Comparator<Person> compareLastNameThenFirstName =
new Comparator<Person>() {
@Override
public int compare(Person p1, Person p2) {
int lastNameComparison =
p1.getLastName().compareTo(p2.getLastName());
return lastNameComparison == 0 ?
p2.getFirstName().compareTo(p2.getFirstName());
lastNameComparison;
}
};
▪
▪
// comparison using the last name
Comparator<Person> compareLastName =
Comparator.comparing(Person::getLastName);
▪
// comparison using the last name
Comparator<Person> compareLastName =
Comparator.comparing(Person::getLastName);
▪
▪
// comparison using the last name and then the first name
Comparator<Person> compareLastNameThenFirstName =
Comparator.comparing(Person::getLastName)
.thenComparing(Person::getFirstName);
▪
▪
// reverses a comparator
Comparator<Person> comp = ...;
▪
▪
long max = Long.max(1L, 2L);
▪
▪
// JDK 7
long l = 3141592653589793238L;
int hash = new Long(l).hashCode(); // -1985256439
// JDK 8
long l = 3141592653589793238L;
int hash = Long.hashCode(l); // - 1985256439
▪
▪
Map<String, Person> map = ...;
map.forEach((key, person) ->
System.out.println(key + " " + person);
▪
▪
Map<String, Person> map = ...;
▪
▪
Map<String, Person> map = ...;
map.put(key, person);
map.putIfAbsent(key, person); // JDK8
▪
▪
Map<String, Person> map = ...;
map.replace(key, person);
▪
▪
Map<String, Person> map = ...;
map.replace(key, person);
map.replace(key, oldPerson, newPerson);
▪
▪
Map<String, Person> map = ...;
map.replace(key, person);
map.replace(key, oldPerson, newPerson);
▪
▪
Map<String, Person> map = ...;
map.remove(key);
▪
Map<String, Person> map = ...;
map.remove(key); // JDK 7
map.remove(key, person); // JDK 8
▪
▪
Map<String, Person> map = ...;
▪
▪
Map<String, Person> map = ...;
▪
▪
Map<String, Person> map = ...;
▪
▪
Map<String, Person> map = ...;
▪
▪
▪
@TestCases({
@TestCase(param=1, expected=false),
@TestCase(param=2, expected=true)
})
public boolean even(int param) {
return param % 2 == 0;
}
▪
▪
@TestCases({
@TestCase(param=1, expected=false),
@TestCase(param=2, expected=true)
})
public boolean even(int param) {
return param % 2 == 0;
}
▪
▪
▪
@TestCase(param=1, expected=false)
@TestCase(param=2, expected=true)
public boolean even(int param) {
return param % 2 == 0;
}
▪
▪
@TestCase(param=1, expected=false)
@TestCase(param=2, expected=true)
public boolean even(int param) {
return param % 2 == 0;
}
▪
▪
▪
▪
▪
▪
▪
@interface TestCase {
int param();
boolean expected();
}
@interface TestCases {
TestCase[] value();
}
▪
@Repeatable(TestCases.class)
@interface TestCase {
int param();
boolean expected();
}
@interface TestCases {
TestCase[] value();
}
▪