Java第03章--3(数组)

整理文档很辛苦,赏杯茶钱您下走!

免费阅读已结束,点击下载阅读编辑剩下 ...

阅读已结束,您可以下载文档离线阅读编辑

资源描述

JavaJavapenggang@mail.hust.edu.cn3.4—————,,—JavanewJava.length1——typearrayName[]type[]arrayName(type)JavaarrayName[]intarrayName[]int[]arrayName1——JavanewJavatypevar_name[]=newtype[size];type[]var_name=newtype[size];int[]a=newint[5];int[]aa=newint[5];Java“”DatedateArray[]Date[]dateArray;DateCC++Java[]1——int[]intArray={1,2,3,4};//4//intnewtypearrayName[]=newtype[arraySize];type[]arrayName=newtype[arraySize];typearrayName[]=newtype[arraySize];nullNullPointExceptionnewarrayName[0]=newtype(paramList);//()…arrayName[arraySize-1]=newtype(paramList);1——StringstringArrar[];//StringstringArray=newString[3];//stringArray3//nullstringArray[0]=newString(“how”);stringArray[1]=newString(“are”);stringArray[2]=newString(“you”);1——newarrayName[index]indexarrayName[2],arrayName[i],arrayName[arrayName.length-1]011——CC++JavalengthintArray.lengthintArrayArrayIndexOutOfBoundsException„Java„SwapInt.java,P1633.9,P159Javajava.util.RandomintlongfloatdoubleGoussianjava.lang.MathRandom()doubleRandom(1)publicRandom()//Javaseed(2)publicRandom(longseed)//(1)publicsynonronizedvoidsetSeed(longseed)//seed(2)publicintnextInt()//(3)publiclongnextLong()//long(4)publicfloatnextFloat()//Float(5)publicdoublenextDouble()//Double(6)publicsynchronizeddoublenextGoussian()//doubleGoussian——Wrapperclass„Java8JavaWrapperclasswrapper:,,„Java8java.langNumberbooleanBooleanintIntegerbyteBytelongLongcharCharacterfloatFloatshortShortdoubleDoubleInteger„IntegerpublicstaticfinalMIN_VALUE=0x80000000;publicstaticfinalMAX_VALUE=0x7fffffff;„IntegerpublicInteger(intvalue){...}publicInteger(Strings){...}„intprimitiveInt=64;IntegerwrappedInt=newInteger(primitiveInt);Stringstr=64;IntegerwrappedInt=newInteger(str);int„inttoString()3publicStringtoString(){...}publicstaticStringtoString(inti){...}publicstaticStringtoString(inti,intradix){...}IntegerIntergerintIntegerintIntegerintIntegera=newInteger(64);Stringstr1=a.toString();//Integer—”40”intb=64;Stringstr2=Integer.toString(b,16);//int—”40”„intpublicstaticintparseInt(Strings){...}publicstaticintparseInt(Strings,intradix){...}inta=Integer.parseInt(486,10);„NumberFormatExceptioninta=Integer.parseInt(99,8);//NumberFormatExceptionInteger„IntegerpublicstaticIntegervalueOf(Strings){...}publicstaticIntegervalueOf(Strings,intradix){...}Integerint“newInteger(Integer.parseInt(s,radix))”parseInt()intnewIntegerintInteger„IntegerintintValue()publicintintValue(){...}Integerx=newInteger(686);inta=x.intValue();//686a„(7)IntegerintpublicbytebyteValue(){...}publicshortshortValue(){...}publiclonglongValue(){...}publicfloatfloatValue(){...}publicdoubledoubleValue(){...}Object1——typearrayName[][]intintArray[][]type[][]arrayName;new—Java——inta[][]=newint[3][4];inta[][]=newint[3][];a[0]=newint[4];a[1]=newint[4];a[2]=newint[4];a[3][4]1——intintArray[][]={{1,2},{2,3},{3,4}};1——1.typearrayName[][]=newtype[arraylength1][arraylength2]inta[][]=newint[2][3]2.Strings[][]=newString[2][];s[0]=newString[2];s[1]=newString[3];s[0][0]=newString(“Good”);s[0][1]=newString(“Luck”);s[1][0]=newString(“to”);s[1][1]=newString(“you”);s[1][1]=newString(“!”);1——1——java.util.Arrays„„Java„„java.utilArrays„java.utilVectorVector„intbinarySearch(typea[],typekey)„a„a„keya„“-(-1)”„booleanequals(typea[],typea2[])„„null„voidfill(typea[],typeval)voidfill(typea[],intfromIndx,inttoIndex,typeval)„a[fromIndx]a[toIndex]„fromIndx==toIndex1——java.util.Arrays1——java.util.Arrays„voidsort(typea[])voidsort(typea[],intfromIndx,inttoIndex)„a[fromIndx]a[toIndex]„fromIndx==toIndex„QuickSortn*log(n)„„JDK1——„java.lang.System„voidarraycopy(Objectsrc,intsrc_position,Objectdst,intdst_position,intlength)„„„„JDKJava2ƒJavaƒJavaƒƒƒƒ

1 / 29
下载文档,编辑使用

©2015-2020 m.777doc.com 三七文档.

备案号:鲁ICP备2024069028号-1 客服联系 QQ:2149211541

×
保存成功