我有这样的行↓从列表中获取确切的元素,但我想多次添加它使用某种类型的数组,如"for"与计数器
list.stream().filter(x -> x.getUserID() == user.getUserID()).collect(Collectors.toList());
list.stream().map(o -> new Object[] { (Object) o }).collect(Collectors.toList();
Run Code Online (Sandbox Code Playgroud)
我有类似的代码,但我不想使用双:
List<Object[]> tmp = new ArrayList<Object[]>();
for (Iterator<?> iterator = tests.getTestData().iterator(); iterator.hasNext();) {
Object objects = iterator.next();
//should have condition like id=id
for (int i = 0; i < t.getInvocationCount(it); i++) {
tmp.add(new Object[] { objects });
}
}
Run Code Online (Sandbox Code Playgroud)
使用流可以满足条件的多个元素?
编辑:
*tests.getTestData() -> returns List
**t.getInvocationCount -> returns int [t is not important cause it is generic]
Run Code Online (Sandbox Code Playgroud)
在通知中我只需要arry中的多个元素
FOR arry TO arry=END DO:
IF arry[i] IS …Run Code Online (Sandbox Code Playgroud) 我有TextView [?]的问题,我初始化textview因为我想让它可滚动但我有一个错误.
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
dc = new DigitalClock(this);
textViewMesssage = new TextView(this);
dc = (DigitalClock) findViewById(R.id.digitalClock1);
textViewMesssage = (TextView) findViewById(R.id.textV);
textViewMesssage.setMovementMethod(new ScrollingMovementMethod());
setContentView(R.layout.main);
addListenerOnButton();
}
public void addListenerOnButton() {
buttonTest = (Button) findViewById(R.id.button_id);
buttonTest.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View arg0) {
Calendar c = Calendar.getInstance();
SimpleDateFormat sdf = new SimpleDateFormat("dd:MMMM:yyyy HH:mm:ss a");
String strDate = sdf.format(c.getTime());
}
});
}
Run Code Online (Sandbox Code Playgroud)
main.xml中
<TextView
android:id="@+id/textV"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:text="MainActivity"
android:layout_gravity="left"
android:scrollbars = "vertical"
/>
<Button
android:id="@+id/button_id"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:text="Hello" …Run Code Online (Sandbox Code Playgroud) 如何使用流解析Generic到Object []?我有过
private static <T> List<Object[]> selectData(List<T> a,
Predicate<T> predicate) {
ArrayList<Object[]> tmp = new ArrayList<Object[]>();
for (T x : a) {
if (predicate.test(x)) {
tmp.add(new Object[] { x });
}
}
return tmp;
}
Run Code Online (Sandbox Code Playgroud)
但我想做的事情如下:
...//
return a.stream().filter(predicate).collect(Collectors.toList());
Run Code Online (Sandbox Code Playgroud)
但我不知道如何将每个元素转换为Object []