This discussion is archived
0 Replies Latest reply: Jul 4, 2013 11:45 AM by coco RSS

compare the values of a list and the values of an array

coco Newbie
Currently Being Moderated

Hi,

 

I need to compare the following values from list and arrays.

My code is:

{code}

public class JavaApplication3 {

 

 

    /**

     * @param args the command line arguments

     */

    public static void main(String[] args) {

        // TODO code application logic hereut

        List<String> l = new ArrayList<String>();

        l.add("test");

        l.add("b");

        String v = "";

        String s = "";

        String[] arr = {"test", "c", "b"};

       

        for (int i = 0; i < l.size(); i++){

            v = "";

            s = "";

            //System.out.println(l.get(i));

            for (int j = 0; j < arr.length; j++){

                if (l.get(i).equals(arr[j])){

                    s = i + "";

                }else{

                    s = arr[i];

                }

                v = v + s + ",";                  

            } 

            System.out.println(v);         

        }

       

    }

}

{code}

I obtain:

0,test,test,

c,c,1

and the output that I need is:

0, c, 1,

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points