Java System類兩個(gè)常用方法代碼實(shí)例
1.System.currentTimeMills():得到當(dāng)前時(shí)間距離時(shí)間原點(diǎn)的毫秒數(shù),返回值是Long類型的整數(shù)。
代碼演示:
public class Demo4 { public static void main(String[] args) { long l = System.currentTimeMillis(); System.out.println(l); }}
運(yùn)行結(jié)果:
2.System.arrayCopy(src,srcpos,des,despos,length):將原數(shù)組src中srcpos位置及其后面length長(zhǎng)度的數(shù)復(fù)制給目標(biāo)數(shù)組des的despos位置。
代碼演示:
import java.util.Arrays;public class Demo4 { public static void main(String[] args) { int[] a={3,7,1,8,5}; int[] b={11,2,16,7,9,0}; //把數(shù)組a索引為3的位置往后2個(gè)數(shù)(8,5)復(fù)制到數(shù)組b索引為2的位置上 System.arraycopy(a,3,b,2,2); System.out.println(Arrays.toString(b)); }}
運(yùn)行結(jié)果:
注意:
(1)目標(biāo)數(shù)組原來(lái)位置上的數(shù)直接被覆蓋了。
(2)數(shù)組索引從0開(kāi)始。
以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持好吧啦網(wǎng)。
相關(guān)文章:
