把对象转成map
时间: 2023-07-27 19:19:27 浏览: 55
Top() && y <= mLetterIndexTextView.getBottom()) {
mIsTouchingLetterIndex = true;
showLetterIndex(get如果你使用的是Java语言,可以使用Java 8中引入的Stream API来将对象转换为Map。具LetterIndex(y));
return true;
}
} else if (e.getAction() == MotionEvent.ACTION_MOVE) {
if (m体实现如下:
假设有一个名为Person的类,包含属性name和age,我们可以将Person对象列表IsTouchingLetterIndex) {
showLetterIndex(getLetterIndex(e.getY()));
return true;
}
} else if (转换为Map,其中key为name,value为age:
```
List<Person> personList = new ArrayList<>();
personList.add(newe.getAction() == MotionEvent.ACTION_UP || e.getAction() == MotionEvent.ACTION_CANCEL) {
mIsTouchingLetterIndex = false;
Person("Alice", 25));
personList.add(new Person("Bob", 30));
personList.add(new Person("Charlie", 35));
hideLetterIndex();
}
return false;
}
@Override
public void onTouchEvent(@NonNull RecyclerView rv, @NonNullMap<String, Integer> personMap = personList.stream()
.collect(Collectors.toMap(Person::getName, Person::getAge));
```
MotionEvent e) {
}
@Override
public void onRequestDisallowInterceptTouchEvent(boolean disallowIntercept) {
}
这里使用了`Collectors.toMap`静态方法,它接受两个参数,第一个参数是key的提取 });
}
private List<AppInfo> getAppInfoList() {
PackageManager pm = getPackageManager();
List<ApplicationInfo> appList函数,第二个参数是value的提取函数。在上面的例子中,`Person::getName`提取了 = pm.getInstalledApplications(PackageManager.GET_META_DATA);
List<AppInfo> appInfoList = new ArrayList<>();
for (Application对象的name属性作为key,`Person::getAge`提取了对象的age属性作为value。
相关推荐
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![-](https://csdnimg.cn/download_wenku/file_type_column_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)