Java Code to PHP code

Source: Internet
Author: User
Java Code to PHP code, the master into
Import Java.util.arraylist;import Java.util.arrays;import Java.util.list;public class Arrayassemble {@ Suppresswarnings ("unchecked") public static void main (string[] args) {string[] Arrofint = {"Red", "orange", "Yellow", "Black"}; @SuppressWa Rnings ("unused") string[] arrOfChar1 = {"L", "XL"}, @SuppressWarnings ("unused") string[] arrOfChar2 = {"Hemp", "acrylic", "See"}; String[] ArrOfChar3 = {"Kui", "Kang"}; String[] Arrofstr = {"Lmy", "Lyb", "MZ", "YX"}; System.out.println ("The following is a combined array");//object[][] Objectsarrays = Assemblearraystoplanerarray (new object[][] {arrofint, ArrOfChar1, ArrOfChar2, arrofchar3,arrofstr}); object[][] Objectsarrays = Assemblearraystoplanerarray (new object[][] { ARROFCHAR1,ARROFCHAR2, ArrOfChar3});//object[][] Objectsarrays = Assemblearraystoplanerarray (new object[][] { ARROFCHAR1,ARROFCHAR2}); int i = 0;for (object[] objarrays:objectsarrays) {i++; SYSTEM.OUT.PRINTLN (i + "=" + arrays.tostring (objarrays));}} Helper method One: Combines a list of an array type or an object type with an array and returns List@suppresswarnings ("unchecked") public static LIst assemblearraytolist (List alist, object[] array) {List arrlist = new ArrayList ();//traverse alist, combine array with alist for (int i = 0; I < alist.size (); i++) {Object obj = alist.get (i),//check whether the Alist element is an array type, if not, directly produce the combined list if (obj instanceof object[]) {object[] Listarr = (obje Ct[]) obj;//The alist element of an array type with array for (int k = 0; k < array.length; k++) {object[] Newlistarr = new Object[listarr.le Ngth + 1];for (int j = 0; J < Listarr.length; J + +) {Newlistarr[j] = listarr[j];} Newlistarr[listarr.length] = Array[k];arrlist.add (Newlistarr);}} else {//alist element of non-array type is combined with array for (int j = 0; J < Array.Length; J + +) {object[] arrobj = {Alist.get (i), Array[j]};a Rrlist.add (Arrobj);}}} return arrlist;} Method Two: Use the two-dimensional array parameter method to return the combined two-dimensional array type and use the recursive @suppresswarnings ("unchecked") public static object[][] Assemblearraystoplanerarray (object[][] objectarrays) {if (objectarrays.length = = 2) {object[] Assembledarray = objectarrays[0];object[] Array = Objectarrays[1];return Assemblearraytoarray (assembledarray, array);} else if (objectarrays.length <= 1) {return objectarrays;} else {object[] Objarray = objectarrays[objectarrays.length- 1];objectarrays = arrays.copyof (objectarrays, objectarrays.length-1); return Assemblearraytoarray ( Assemblearraystoplanerarray (objectarrays), Objarray);}} Method Two auxiliary methods: combine an array type or two-dimensional array type with an array and return a two-dimensional array public static object[][] Assemblearraytoarray (object[] Assembledarray,object [] array) {int Lenassarray = Assembledarray.length;int Lenarray = array.length;object[][] Objarrays = new OBJECT[LENASSARR AY * lenarray][];for (int i = 0; i < Lenassarray; i++) {Object obj = assembledarray[i];if (obj instanceof object[]) {Ob Ject[] Objarr = (object[]) obj;int Lenobjarr = objarr.length;for (int k = 0; k < Lenarray; k++) {//copy Objarr array to Newlista RR array and add its length to a object[] Newlistarr = arrays.copyof (Objarr, Lenobjarr + 1);//Assign the k+1 element of the array to the last element of the Newlistarr array, and assigns the Newlistarr to the k+1 element of the objarrays array Newlistarr[lenobjarr] = Array[k];objarrays[lenarray * i + K] = Newlistarr;}} else {for (int j =0; J < Lenarray; J + +) {object[] Newobjarray = {obj, array[j]};objarrays[lenarray * i + j] = Newobjarray;}}} return objarrays;}}
  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.