• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Divide a vector

 
Shaista shaikh
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
having a list of person name (suppose 5) want to print those name like 2 , 2 & 1 one by one in java
 
aslam parveez
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Pls be clear about what exactly you want to do.
If you have list a list of Names , do you want to hold them in a collection with Name,Value pairs ?
 
Naveen Verma
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't know if u r trying to achive something like this...

List lst = new ArrayList();
lst.add("item_1");
lst.add("item_2");
lst.add("item_3");
lst.add("item_4");
lst.add("item_5");
double group = Math.round(lst.size()/2.0);
int p=0;
for (; p < (group +2); ) {
String str = null;
str = (String)lst.get(p);
if ((p+1) < lst.size())
str = str + " "+ lst.get(p+1);
p = p+ 2;
System.out.println("str="+str);
}

-Naveen
 
Ernest Friedman-Hill
author and iconoclast
Marshal
Pie
Posts: 24212
35
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's have this stimulating discussion in Java in General (Beginner).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic