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: Hello experts, i here gave a program which i likes to print the duplicates in an arraylist, but getting ConcurrentModificationException.. help me get solved

  1. #1
    Member vigneshwaran's Avatar
    Join Date
    Nov 2012
    Location
    Chennai, TamilNadu
    Posts
    35
    My Mood
    Cheerful
    Thanks
    7
    Thanked 1 Time in 1 Post

    Angry Hello experts, i here gave a program which i likes to print the duplicates in an arraylist, but getting ConcurrentModificationException.. help me get solved

    package silverbullet;
     
    import java.util.ArrayList;
     
    public class StringProcessing {
     
    	public static ArrayList<String> list=new ArrayList<String>(10);
    	public static ArrayList<String> deleted=new ArrayList<String>(10);
    	public void set()
    	{
    	list.add("hello");
    	list.add("hi");
    	list.add("hello");
    	list.add("bye");
    	}
    	public void print()
    	{
    		for(int i=0;i<deleted.size();i++)
    		{
    			System.out.println(deleted.get(i));
    		}
    	}
    	public static void main(String[] args) {
    		StringProcessing sp=new StringProcessing();
    		sp.set();
     
    		for(Object l:list)
    		{
    			int c=0;
    			String s=l.toString();
    			for(int i=0;i<(list.size()-c);i++)
    			{
     
    				if(s==list.get(i+1))
    				{
    					list.remove(i+1);
    					deleted.add(s);
    					c=c+1;
    				}
    			}
    		}
                          sp.print();
    	}
     
    }


    i tried lot, changed code. but getting the exception of "ConcurrentModificationException"
    my concept of this program is to print the items which are duplicated in the ArrayList named list, and storing the duplicates in the new ArrayList named deleted.

    Help me fix this problem


  2. #2
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Hello experts, i here gave a program which i likes to print the duplicates in an arraylist, but getting ConcurrentModificationException.. help me get solved

    Please find below the answer to ur question:

    1. firstArray is used to store the list of array elements which contains the duplicate entries
    2. filterList is used to store the elements which has no duplicate entries ....
    HAPPY && ENJOY coding ...........

    ...code removed

  3. The Following User Says Thank You to mikeclark For This Useful Post:

    vigneshwaran (October 24th, 2013)

  4. #3
    Super Moderator Norm's Avatar
    Join Date
    May 2010
    Location
    Eastern Florida
    Posts
    25,042
    Thanks
    63
    Thanked 2,708 Times in 2,658 Posts

    Default Re: Hello experts, i here gave a program which i likes to print the duplicates in an arraylist, but getting ConcurrentModificationException.. help me get solved

    "ConcurrentModificationException"
    Use the old style for loop that uses an index, not the new for each style.
    If you don't understand my answer, don't ignore it, ask a question.

  5. The Following User Says Thank You to Norm For This Useful Post:

    vigneshwaran (October 24th, 2013)

  6. #4
    Administrator copeg's Avatar
    Join Date
    Oct 2009
    Location
    US
    Posts
    5,320
    Thanks
    181
    Thanked 833 Times in 772 Posts
    Blog Entries
    5

    Default Re: Hello experts, i here gave a program which i likes to print the duplicates in an arraylist, but getting ConcurrentModificationException.. help me get solved

    @mikeclark, please read the forum rules and the following:
    http://www.javaprogrammingforums.com...n-feeding.html

  7. #5
    Junior Member
    Join Date
    Dec 2012
    Posts
    7
    Thanks
    0
    Thanked 1 Time in 1 Post

    Default Re: Hello experts, i here gave a program which i likes to print the duplicates in an arraylist, but getting ConcurrentModificationException.. help me get solved

    yes . I will be careful on that Thanks !!

Similar Threads

  1. Replies: 1
    Last Post: December 3rd, 2012, 02:35 PM
  2. Duplicates in Arraylist
    By tcstcs in forum Collections and Generics
    Replies: 1
    Last Post: September 15th, 2011, 06:23 PM
  3. Replies: 24
    Last Post: April 14th, 2009, 03:43 PM
  4. [SOLVED] Java program error in displaying Output
    By crazydeo in forum AWT / Java Swing
    Replies: 9
    Last Post: May 14th, 2008, 10:42 AM