• Post Reply Bookmark Topic Watch Topic
  • New Topic

How to add an element to a list at a specific index  RSS feed

 
sunil khichar
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
how to add element inside list specified index
 
Joanne Neal
Rancher
Posts: 3742
16
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you had a look at the List javadoc to see if there is a method that will do this ?
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There is one List implementation that will let you do that. Figuring out the correct one is left as an exercise for the student. Start with that link that Joanne gave you.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
And welcome to the Ranch! As you may have figured out by now, we're here to help you learn, not give you answers. I hope you are here for the same reason.
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
J. Kevin Robbins wrote:There is one List implementation that will let you do that.

??
There are at least four general purpose List implementations in the standard API as well as a couple of more domain specific ones that support the method in question.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You made me go read the apis. Of all the implementing classes, I've only used 3 of them so I was thinking of the one I've used, a rather common one. Reading some of the others, I'm not even sure when I would use them.

Something new every day.
 
Rico Felix
Ranch Hand
Posts: 411
5
IntelliJ IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
J. Kevin Robbins wrote:You made me go read the apis. Of all the implementing classes, I've only used 3 of them so I was thinking of the one I've used, a rather common one. Reading some of the others, I'm not even sure when I would use them.

Something new every day.


Joanne is indeed atop of her Java game... She's so
 
Joanne Neal
Rancher
Posts: 3742
16
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
J. Kevin Robbins wrote:You made me go read the apis.

Your first post made me do the same. I knew there were at least a couple, but I'd forgotten that Vector had been retrofitted to implement it as well.
And I also came across a new one to me (CopyOnWriteArrayList). Not sure I'll ever use it, but nice to know it exists.
 
J. Kevin Robbins
Bartender
Posts: 1801
28
Chrome Eclipse IDE Firefox Browser jQuery Linux MySQL Database Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's one that puzzled me, too. I can't imagine why I would ever need it. I did a quick search and found only one book dedicated to Java collections and one book about generics and collections. It looks like I need to read both of them and expand my horizons a bit.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!