Vous trouverez ci-dessous les 12 méthodes de fonctionnement du tableau qui obtiennent le plus de votes dans StackOverflow.
1. Déclarer un tableau
String [] aArray = new String [5]; String [] Barray = {"A", "B", "C", "D", "E"}; String [] carray = new String [] {"A", "B", "C", "D", "E"};2. Sortir un tableau
int [] intArray = {1, 2, 3, 4, 5}; String IntArrayString = Arrays.ToString (IntArray); // Imprimer directement imprimera le valeur de référence System.out.println (intarray); // [i @ 7150bd4d System.out.println (IntArrayString); // [1, 2, 3, 4, 5]3. Créez une liste de tableaux à partir d'un tableau
String [] stringarray = {"a", "b", "c", "d", "e"}; ArrayList <string> arrayList = new ArrayList <string> (arrays.aslist (stringArray)); System.out.println (ArrayList); // [a, b, c, d, e]4. Vérifiez si un tableau contient une valeur
String [] stringarray = {"a", "b", "c", "d", "e"}; booléen b = arrays.aslist (stringArray) .Contains ("a"); System.out.println (b); // vrai 5. Concaténer deux tableaux
int [] intArray = {1, 2, 3, 4, 5}; int [] IntArray2 = {6, 7, 8, 9, 10}; // la bibliothèque APache Commons Lang int [] combinentArray = arrayutils.addall (intarray, intArray2);6. Déclarer un tableau en ligne (tableau en ligne)
Méthode (new String [] {"A", "B", "C", "D", "E"});
7. Mettez l'élément de tableau fourni dans une chaîne
// contenant la liste fournie des éléments // APACHE Common Lang String j = stringUtils.join (new String [] {"A", "B", "C"}, ","); System.out.println (J); // a, b, c8. Convertir une liste de tableaux en un tableau
String [] stringarray = {"a", "b", "c", "d", "e"}; ArrayList <string> arrayList = new ArrayList <string> (arrays.aslist (stringArray)); String [] stringarr = new String [arrayList.size ()]; ArrayList.toArray (StringArr); pour (String s: stringarr) System.out.println (s);9. Convertir un tableau en réglage
Set <string> set = new HashSet <string> (arrays.aslist (stringArray)); System.out.println (set); // [d, e, b, c, a]
10. Inverse un tableau
int [] intArray = {1, 2, 3, 4, 5}; Arrayutils.reverse (intarray); System.out.println (arrays.tostring (intarray)); // [5, 4, 3, 2, 1]11. Retirer les éléments du tableau
int [] intArray = {1, 2, 3, 4, 5}; int [] supprimé = arrayutils.reMoveElement (IntArray, 3); // Créer un nouveau système Array.out.println (arrays.tostring (supprimé));12. Convertir les entiers en tableaux d'octets
octet [] octets = bytebuffer.Allocation (4) .puntInt (8) .Array (); pour (byte t: bytes) {System.out.format ("0x% x", t); }Ce qui précède est une compilation d'informations sur le tableau Java. Nous continuerons d'ajouter des informations pertinentes à l'avenir. Merci pour votre soutien pour ce site Web!