3 Responses

Page 1 of 1
  1. April 6, 2012 at 1:20 am | | Reply

    I have tried this way, but i can not succeeded.

    public class Opdracht1 {

    /**
    * @param args the command line arguments
    */

    public static void main(String[] args) {

    String A[] = { “Joseph”,”Ariana”,”Xena”,”Rene”,”Peter”,”Diana”,
    “Rihanna”};
    String B[] = {“Madona”,”Diddy”,”Joe”,”Alice”};

    for(int j = 0; j < A.length; j++) {
    for(int i = j + 1; i < A.length; i++) {
    if(A[i].compareToIgnoreCase(A[j]) < 0) {
    String K = A[j];
    A[j] = A[i];
    A[i] = K;
    }
    }

    List list = new ArrayList(Arrays.asList(A));
    list.addAll(Arrays.asList(B));
    Object[] C = list.toArray();

    System.out.println(Arrays.toString(C));

    }
    }
    }

  2. April 5, 2012 at 1:19 am | | Reply

    public static void main(String[] args) {

    String A[] = { “Joseph”,”Ariana”,”Xena”,”Rene”,”Peter”,”Diana”,
    “Rihanna”};
    String B[] = {“Madona”,”Diddy”,”Joe”,”Alice”};

    for(int j = 0; j < A.length; j++) {
    for(int i = 0 ; i < B.length; i++) {
    if(B[i].compareToIgnoreCase(A[j]) < 0) {
    String K = A[j];
    A[j] = B[i];
    B[i] = K;
    }
    }
    System.out.println(A[j]);

    }

    }
    }

    how to get both arrays combined and sorted using comapreTo method.

Leave a Reply