亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

toArray()方法需要傳入一個IntFunction,可是String[]::new 跟int一點關系都沒有,怎么理解?

public?static?void?main(String[]?args)?{
????Stream<String>?stream?=?Stream.of("1",?"2",?"3");




????//?這里的toArray()方法需要傳入一個IntFunction,可是String[]::new?跟int一點關系都沒有
????String[]?strArray?=?stream.toArray(String[]::new);




}

//?這里的toArray()方法需要傳入一個IntFunction,可是String[]::new?跟int一點關系都沒有,怎么理解?


http://img1.sycdn.imooc.com//5e4e55290001d21307210297.jpg

正在回答

4 回答

String[]::new?means?size -> new String[size].

https://stackoverflow.com/questions/44310226/what-does-stringnew-mean

0 回復 有任何疑惑可以回復我~
Returns?an?array?containing?the?elements?of?this?stream,?using?the
*?provided?{@code?generator}?function?to?allocate?the?returned?array
返回一個包含此流元素的數組,使用提供的函數來分配返回的數組

@param?generator?a?function?which?produces?a?new?array?of?the?desired
*??????????????????type?and?the?provided?length
生成所需類型和提供長度的新數組的函數

String[]::new? ,ctrl+鼠標左擊 :: ?

你進去就是IntFunction接口。

stream01.toArray(Person[]::new);?改成Person類也可以


0 回復 有任何疑惑可以回復我~

同問,還是沒理解

0 回復 有任何疑惑可以回復我~
?@param?generator?a?function?which?produces?a?new?array?of?the?desired?type?and?the?provided?length

產生所需類型和所提供長度的新數組的函數

0 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

toArray()方法需要傳入一個IntFunction,可是String[]::new 跟int一點關系都沒有,怎么理解?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號