Java使用List类的数据时,像判断某一个位置(N),是否为null值,更高效的写法.
PHPz
PHPz 2017-04-18 10:36:17
0
4
517
PHPz
PHPz

学习是最好的投资!

reply all(4)
Ty80

Using Java8 only requires one line of code

List<Integer> list = new ArrayList<>();
if (list == null || list.isEmpty()){
    return Collections.emptyList();
}
return list.stream().filter(Objects::nonNull).limit(2).collect(Collectors.toList());
PHPzhong

ArrayListget(index)Don’t worry about the efficiency of the method. Your problem description and title seem unrelated. Can you understand it?

左手右手慢动作

When the number of data items is determined, the backend only needs to return two items, and then it can be traversed directly. There is no need to make it so complicated...

Ty80

What does it mean that your question is difficult to understand? ! !
Do you mean something like “display in pages”? And dynamically return data based on the number of lists?
If this is the case, then you can use ArrayList and use the sort method of ArrayLiast to sort. After sorting, you can pick whichever item you want without any confusion.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template