Results 1 to 4 of 4
  1. #1
    whizzz is offline Member
    Join Date
    Oct 2010
    Posts
    3
    Rep Power
    0

    Default Problem- arraylist

    hello there,
    im adding some object references to arraylist.
    the problem is while adding objects, arraylist leaves one index empty.
    for example (pseudo code);
    for each object in arraylist;
    print the index of the object;

    output is;
    1
    2
    3
    4
    6 (????? where is 5!! )
    7
    8

    it skips the 5th index and its empty. the output of 5th index is (-1).
    any ideas ?

  2. #2
    javanb is offline Member
    Join Date
    Dec 2010
    Posts
    10
    Rep Power
    0

    Default

    Please post the exact code that produces this weird behavior.

  3. #3
    whizzz is offline Member
    Join Date
    Oct 2010
    Posts
    3
    Rep Power
    0

    Default java code

    here is the java code of my problem, thanks.

    Java Code:
          List<Node<E>> eachone=new ArrayList<Node<E>>();
    		List<Node<E>> unique=new ArrayList<Node<E>>();
    		Iterator<Node<E>> it=graph.iterator();
    		
    		while (it.hasNext()){
    			Node<E> rootr=it.next();
    			if (!unique.contains(rootr)){
    				unique.add(rootr);
    				rootr.num=unique.indexOf(rootr);
    				eachone=bfs(graph,rootr);
    				Iterator<Node<E>> it2=eachone.iterator();
    					while(it2.hasNext()){
    						Node<E> check=it2.next();		
    							if (!unique.contains(check)){
    								unique.add(check);
    								check.num=unique.indexOf(check);
    			 }
    		 }
    		}
    		}

  4. #4
    javanb is offline Member
    Join Date
    Dec 2010
    Posts
    10
    Rep Power
    0

    Default

    What is Node<E>? Which class library does it import from?

    Also, please provide the code that prints it, as the code you provide does not match your original pseudo code.

Similar Threads

  1. ArrayList problem.
    By keo in forum New To Java
    Replies: 4
    Last Post: 10-15-2010, 12:22 PM
  2. Arraylist problem
    By keo in forum New To Java
    Replies: 3
    Last Post: 05-28-2010, 11:38 AM
  3. ArrayList problem
    By brian.baert in forum New To Java
    Replies: 8
    Last Post: 03-06-2010, 02:49 PM
  4. Hey! ArrayList problem here
    By Samgetsmoney in forum New To Java
    Replies: 31
    Last Post: 02-20-2009, 01:39 AM
  5. ArrayList problem
    By khamuruddeen in forum New To Java
    Replies: 7
    Last Post: 12-22-2007, 06:46 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •