动态改变数组的长度
/ ** * réalise un tableau avec une nouvelle taille et copie le contenu * * de l'ancien tableau vers le nouveau tableau. * * @param oldArray l'ancien tableau, à réaffecter. * * @param newize la nouvelle taille de tableau. * * @return un nouveau tableau avec le même contenu. * * / objet statique privé ResizeArray (objet OldArray, int newSize) {int oldize = java.lang.reflect.array.getLength (oldArray); Class elementType = oldArray.getClass (). GetComponentType (); Objet newArray = java.lang.reflect.array.newinstance (elementType, Newsize); int preserveLast = math.min (oldSize, Newsize); if (preservelfength> 0) System.ArrayCopy (OldArray, 0, NewArray, 0, PreservelFength); retourner NewArray; } // Routine de test pour resizearray (). public static void main (String [] args) {int [] a = {1,2,3}; a = (int []) resizearray (a, 5); a [3] = 4; a [4] = 5; pour (int i = 0; i <a.length; i ++) System.out.println (a [i]); }代码只是实现基础方法 , 详细处理还需要你去 codage 哦 >>
把 Array 转换成 Carte
importation java.util.map; import org.apache.commons.lang.arrayutils; classe publique Main {public static void main (String [] args) {String [] [] Pays = {{"États-Unis", "New York"}, {"Royaume-Uni", "Londres"}, {"Pays-Bas", "Amsterdam"}, {"Japon", "Tokyo"}, {"France", "Paris"}}; Map countrycapitals = arrayutils.tomap (pays); System.out.println ("La capitale du Japon est" + countrycapitals.get ("Japon")); System.out.println ("La capitale de la France est" + countrycapitals.get ("France")); }}