Im Folgenden finden Sie die 12 Array -Betriebsmethoden, die die meisten Stimmen in Stackoverflow erhalten.
1. deklarieren Sie ein Array
String [] aarray = new String [5]; String [] Barray = {"A", "B", "C", "D", "E"}; String [] carray = new String [] {"a", "b", "c", "d", "e"};2. Ausgabe eines Arrays
int [] intarrray = {1, 2, 3, 4, 5}; String intarrrayString = arrays.toString (IntArray); // DRUCK DIRT DRUCKE REFERENZWEISE SYSTEM SYSTEM.OUT.println (IntArray); // [i@7150bd4d system.out.println (IntArrayString); // [1, 2, 3, 4, 5]3. Erstellen Sie eine Array -Liste aus einem Array
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. Überprüfen Sie, ob ein Array einen Wert enthält
String [] stringarray = {"a", "b", "c", "d", "e"}; boolean b = arrays.aslist (stringArray) .Contains ("a"); System.out.println (b); // WAHR 5. verkettet zwei Arrays
int [] intarrray = {1, 2, 3, 4, 5}; int [] intarrray2 = {6, 7, 8, 9, 10}; // Apache Commons Lang Library int [] kombinIntArray = arrayutils.addall (Intarrray, Intarrray2);6. ein Inline -Array deklarieren (Array Inline)
Methode (neue String [] {"A", "B", "C", "D", "E"});
7. Geben Sie das bereitgestellte Array -Element in eine Zeichenfolge ein
// die angegebene Liste der Elemente enthält // Apache Common Lang String j = stringutils.join (neue String [] {"A", "B", "C"}, ","); System.out.println (j); // a, b, c8. Konvertieren Sie eine Array -Liste in ein Array
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); für (String S: Stringarr) system.out.println (s);9. Konvertieren Sie ein Array in eingestellt
Set <string> set = new Hashset <string> (arrays.aslist (stringArray)); System.out.println (set); // [d, e, b, c, a]
10. umgekehrt ein Array
int [] intarrray = {1, 2, 3, 4, 5}; Arrayutils.Reverse (Intarrray); System.out.println (Arrays.toString (IntArray)); // [5, 4, 3, 2, 1]11. Elemente aus Array entfernen
int [] intarrray = {1, 2, 3, 4, 5}; int [] entfernt = arrayutils.removeElement (intarrray, 3); // Erstellen Sie ein neues Array -System.out.println (Arrays.toString (entfernt));12. Wandeln Sie Ganzzahlen in Byte -Arrays um
byte [] bytes = bytebuffer.alcode (4) .putint (8) .Array (); für (byte t: bytes) {system.out.format ("0x%x", t); }Das obige ist eine Zusammenstellung von Java -Array -Informationen. Wir werden in Zukunft weiterhin relevante Informationen hinzufügen. Vielen Dank für Ihre Unterstützung für diese Website!