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.

Results 1 to 5 of 5

Thread: Map.entry

  1. #1
    Junior Member
    Join Date
    Jun 2014
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Map.entry

    How I can set key to the newly created Map.Entry as it just have the methos as setValue()

  2. #2
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Map.entry

    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.

  3. #3
    Junior Member
    Join Date
    Jun 2014
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Map.entry

    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);
    }
    }
    }

  4. #4
    Senior Member
    Join Date
    Jul 2013
    Location
    Europe
    Posts
    666
    Thanks
    0
    Thanked 121 Times in 105 Posts

    Default Re: Map.entry

    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.

  5. #5
    Junior Member
    Join Date
    Jun 2014
    Posts
    13
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Map.entry

    we can duplicate to the arraylist, and to add while iterating we use ListIterator

Similar Threads

  1. Array entry
    By greenie1234 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: March 13th, 2014, 08:00 AM
  2. User entry needs to be exactly 5 digits
    By tyneframe in forum Java Theory & Questions
    Replies: 4
    Last Post: September 29th, 2012, 09:54 PM
  3. Replies: 9
    Last Post: September 1st, 2012, 07:25 AM
  4. How to sort a Map.Entry in a for loop?
    By Porknbeans in forum Collections and Generics
    Replies: 1
    Last Post: March 23rd, 2012, 07:02 AM
  5. need help w/ entry level homework...
    By rbread80 in forum What's Wrong With My Code?
    Replies: 6
    Last Post: October 3rd, 2010, 10:24 PM