Why is the debugger showing that it is skipping my loop in this method

/**
	 * Adds an item to the list.  This method assumes that the list is already
	 * sorted in alphabetical order based on the names of the items in the list.
	 * 
	 * The new item will be inserted into the list in the appropriate place so
	 * that the list will remain alphabetized by names.
	 * 
	 * In order to accomodate the new item, the internal array must be re-sized 
	 * so that it is one unit larger than it was before the call to this method.
	 *  
	 * @param itemToAdd refers to a Listable item to be added to this list
	 */
	public void add(Listable itemToAdd) {
		
		Listable[] items2=new Listable[this.items.length+1];
		for(int x=0;x<items.length;x++){                  //this loop and others
			items2[x]=items[x];
		}
		items2[items2.length-1]=itemToAdd;
		
		String[] s=new String[items.length];
		
		for(int x=0;x<items.length;x++){
			
			s[x]=this.items[x].getName();			
			
		}
		
		String nameitem=itemToAdd.getName();
		boolean go=true;
		int count=0;
		for(int x=0;x<items2.length;x++){
			
			if(go){
				
				if(nameitem.compareTo(s[x])>0){
					items2[x]=this.items[x];
				}
				else{
					
					for(int g=x;g<items2.length;g++){
						items2[x]=this.items[x+1];
					}
					go=false;
				}
				
				
			}
			
		}
		
		
		items=items2;
		
	}

What is the length of the items array?

Maybe you need to special-case the situation where you are adding the first item to a previously empty list (items.length == 0)?

the constructor starts the size at zero...does that help?? thx so far

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.