RecyclerView更新数据和定位到最底部/冒泡排序优化
定位到底部:
第一种方法:
recycleView.smoothScrollBy(distance,duration);
第二种方法:
rRecycleView.smoothScrollOffset(offset);
第三种方法:
int itemCount = adapter.getItemCount()-1;
recyclerView.smoothScrollToPosition(itemCount);
冒泡排序优化之一
int[] ints = {95, 85, 12, 52, 64, 74, 105, 502, 4, 7, 6, 1, 74, 60, 141, 19, 34, 45, 59};
int temp=0;
int flag = 0;
for (int i = 0; i < ints.length - 1; i++) {
flag = 0;
for (int j = 0; j < ints.length - 1-i; j++) {
if (ints[j] > ints[j + 1]) {
temp = ints[j+1];
ints[j+1] = ints[j];
ints[j] = temp;
flag=1;
}
}
if (flag == 0) {
break;
}
Log.e("####",Arrays.toString(ints));
}