Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

LinkedList

Status
Not open for further replies.

filipe29

Programmer
Jan 14, 2006
23
PT
Hi.I want to return a value inside of a LinkedList with the method get,i have:

this.sentidoActual =(int)sentidos.get(8);

sentidoActual is a integer and when i do that i receive the following error:

"Formiga.java": inconvertible types; found : java.lang.Object, required: int at line 23, column 46
 
Use this :

this.sentidoActual =((Integer)sentidos.get(8)).intValue();

You cannot cast between objects and primitive data types. You must first cast the Object to an Integer object, and then extract the primitive int from that.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Yes but how do i do this:

if (sentidoActual==0)...

I test with intValue()but dont work.
 
Well thats not what you actually asked was it ? You asked how to convert a value stored as an Object into an int.

I don' really understand what you mean by your second question ... perhaps you should explain what exactly you are trying to do.

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Ok.What im trying to do is a linkedlist of an integer values.I have:

private static LinkedList sentidos= new LinkedList();
for (int i=0;i<8;i++) sentidos.add(new Integer(i));

Now i want to check if the index of the linkedlist has the integer 0 for example.
 
So :

Code:
for (int i = 0;  ... rip through list ...) {
  int val = ((Integer)sentidos.get(i)).intValue();
  if (val == ) {
    // bla
  } else {
    // bla bla
  }
}

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
Ok.Thanks.By the way how can i do a next of a linkedlist and return the value?

Like this:

sentidos.iterator().next();
sentidoActual.intvalue()=sentidos.get("index");

Thanks
 
Not sure what you are asking really ...

This is one way of walking through a LinkedList object :

Code:
for (int i = 0; i < sentidos.size(); i++) {
  int val = ((Integer)sentidos.get(i)).intValue();
  if (val == 0) {
    // bla
  } else {
    // bla bla
  }
}

--------------------------------------------------
Free Java/J2EE Database Connection Pooling Software
 
I have made it.Thanks.Do you know how to put the LinkedList circular??
 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top