import java.util.*; import java.util.function.Predicate; import java.util.Comparator;
import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List;
// Sort test // https://techacademy.jp/magazine/34841 class Test1 { public static void sort test () {
//小さい順
// List
// Collections.sort(num1);
// for (Integer a : num1) {
// System.out.println(a);//35 72 100
// }
List<Integer> num1 = new ArrayList<>(Arrays.asList(72,100,86));
Collections.sort(num1,new java.util.Comparator<Integer>(){
@Override
public int compare(Integer i1,Integer i2) {
System.out.println(i1);
return i2 - i1;
}
});
// for (Integer a : num1) {
// System.out.println(a); //100 72 35
// }
}
}
public class Main { public static void main(String[] args) throws Exception { // Your code here! Test1. Sort test ();
me test = new me();
// Part 1 Method chain story // In other words, narrow down the index range of the number of pages // Example of making a list: 100 cases, 10 cases each on the 5th page, 50-60, etc. // Extract the element Extract and put it in list format
// showUserList = IntStream.range(0, allUserList.size())
// .filter(index -> index >= (currentPage - 1) * showNumber && index < currentPage * showNumber)
// .mapToObj(allUserList::get).collect(Collectors.toList());
String Result = test.test (). Substring (2,4);
String Result = test.test ();
System.out.println (result);
// Part 2 lambda expression, anonymous function story //index -> index >= (currentPage - 1) * showNumber && index < currentPage * showNumber //ここの処理はメソッド渡しと言って、メソッドにメソッドそのものを渡す事が出来ます書き方はラムダ式、無名関数とも呼ばれます。
// If you rewrite the contents // In the ○○ method, the argument is an int type arg variable, and the process means that arg and 1 are compared. If all are omitted, it will be written like this. boolean keltuka = test.test2(arg -> arg == 1); System.out.println(keltuka);
//Comparatorインターフェースとは(compareToとは一致しているか調べるメソッドです)
// If o1 <o2, -1
// 0 if o1 == o2
// o1> o2 then -1
// Comparator
class me{ public String test() { System.out.println("kazuki"); return "kazuki"; }
public boolean test2(Predicate<Integer> predicate)
{
Integer argument = 1;
if (predicate.test(argument)) {
return true;
} else {
return false;
}
}
}
Recommended Posts