my dog learned polymorphism
The moose likes Beginning Java and the fly likes Add(index i, Object o) method of arraylist showing random behaviour Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Add(index i, Object o) method of arraylist showing random behaviour" Watch "Add(index i, Object o) method of arraylist showing random behaviour" New topic
Author

Add(index i, Object o) method of arraylist showing random behaviour

vikas bisla
Greenhorn

Joined: Jul 17, 2010
Posts: 5
dmAcc12.dmTree[0].clsAppAddr.lstPort.add(0,portNode); it is adding at 11 position in the arraylist and first 10 entries in the arraylist are null. It shows first index = 11 , lastIndex = 12 and first 10 postion are null.

vikas bisla
fred rosenberger
lowercase baba
Bartender

Joined: Oct 02, 2003
Posts: 9955
    
    6

Thanks for letting us know.

Or...did you have an actual question?


Never ascribe to malice that which can be adequately explained by stupidity.
vikas bisla
Greenhorn

Joined: Jul 17, 2010
Posts: 5
It should add at 0th position .why it is adding at 11th postion.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

What's "firstIndex" and "lastIndex"?
vikas bisla
Greenhorn

Joined: Jul 17, 2010
Posts: 5
while deuging in ecllipse it was showing first index = 11 and last index = 12 but actually adding at 0th position. thanks for your reply.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Post the declaration and construction of the member.

(Is all of the code a trainwreck of leaking internal details like the line you posted?!)
vikas bisla
Greenhorn

Joined: Jul 17, 2010
Posts: 5
dmAcc12.dmTree[0].clsAppAddr.lstPort.add(portNode); Adding at 0th position in this case first index = 0 and last index = 1 but

dmAcc12.dmTree[0].clsAppAddr.lstPort.add(0,portNode); Adding at 11th position in this case first index = 11 and last index = 12
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

David Newton wrote:Post the declaration and construction of the member.
vikas bisla
Greenhorn

Joined: Jul 17, 2010
Posts: 5
public class DmAcc12SubTree
{



public App_DMAcc12_AppAddr_T clsAppAddr = new App_DMAcc12_AppAddr_T();
public App_DMAcc12_AppAuth_T clsAppAuth = new App_DMAcc12_AppAuth_T();



public class AppNode
{
public char cFormat;
public long lSize;
public String straucData;
};





public class App_DMAcc12_Port_T
{
public char cPort_modified[] = new char[DmAcc12Constants.APP_DMACC_MAX_PORT] ; //'T'/'F'->InTact/Ruptured
public ArrayList<AppNode> lstPortId = new ArrayList<AppNode>();
public ArrayList<AppNode> lstPortNbr = new ArrayList<AppNode>();
} ;




}


DmAcc12SubTree.AppNode appNode = null;
DmAcc12SubTree.App_DMAcc12_Port_T portNode = null;

portNode = dmAcc12.dmTree[0].new App_DMAcc12_Port_T() ;

appNode = dmAcc12.dmTree[0].new AppNode();
appNode.cFormat = 147;
appNode.straucData = "TestData";
appNode.lSize = "TestData".length();

portNode.lstPortId.add(0,appNode);
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Wow, that's... hard to read.

If it's a straight JSE ArrayList I have no idea why it would be getting screwed up internally unless there's more to it than what we see here.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Add(index i, Object o) method of arraylist showing random behaviour
 
Similar Threads
ArrayList in Struts
String tokenizer
check my code please?
Need your's Help
ArrayList