How I can set key to the newly created Map.Entry as it just have the methos as setValue()
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
How I can set key to the newly created Map.Entry as it just have the methos as setValue()
You cant.
There might be specific implementations that could make it possible, but its not recommended to even try this.
Just remove the value from the map and put it back inside with a different key if you wish to change the key for a value.
Ok thanks Cornix..
I have one more query whenever i'm adding the element to the list using listIterator, im getting outOfMemorryError
below is the code snippet I need to know why it should add the entry into the lsit
package com.learning;
import java.util.ArrayList;
import java.util.List;
import java.util.ListIterator;
public class TestFab {
public static void main(String[] args) {
List<Integer> list = new ArrayList<Integer>();
list.add(1);
list.add(12);
list.add(3);
list.add(4);
list.add(5);
ListIterator<Integer> itr = list.listIterator();
while (itr.hasNext()) {
itr.add(1);
}
}
}
Try to go through your example by hand on a piece of paper and think about it. Only do what your code says, not what you think that your code says.
Pay close attention to the iteration and what the iterator is currently pointing to.
we can duplicate to the arraylist, and to add while iterating we use ListIterator