-1

Example:

list1 : apple,mango,grapes

list2: orange,gauva,cherry

I want the out to be :

apple,orange

mango,gauva

grapes,cherry.

And should be able to display the above output in the form of link on jsp.Please help me out for this .

Community
  • 1
  • 1
Divya K M
  • 1
  • 2
  • I don't know what JSP is, but the comma thingy should be easy. Iterate through both lists simultaneously and take one element from either and add a comma between them. If they're unequal in size, handle that the way you wish (you did not specify) – Vucko Mar 14 '16 at 18:47
  • are both list the same size??? – ΦXocę 웃 Пepeúpa ツ Mar 14 '16 at 18:50

1 Answers1

0

there are many approaches to do this:

here is one:

If both list are the same size:

final List<String> l1 = new ArrayList<String>();
final List<String> l2 = new ArrayList<String>();
l1.add("mango");
l1.add("apple");
l1.add("grappes");

l2.add("orange");
l2.add("guava");
l2.add("cherry");

for (int i = 0; i < l1.size(); i++) {
    System.out.println(l1.get(i) + "," + l2.get(i));
}

this will print:

mango,orange

apple,guava

grappes,cherry

Community
  • 1
  • 1
ΦXocę 웃 Пepeúpa ツ
  • 47,427
  • 17
  • 69
  • 97