Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

NoSuchElementException in StringTokenizer

807597Mar 3 2005 — edited Mar 3 2005
hi there guys i have this exception when sorting the StringTokenizers this is my code...
public static StringTokenizer[] bubbleSort(StringTokenizer[] s){
    	StringTokenizer temp;
    	for(int pass=0;pass<s.length-1;pass++){
    		for(int index=0;index<s.length-1;index++){
    			if(compare(s[index],s[index+1])){
    				temp = s[index];
    				s[index] = s[index+1];
    				s[index+1] = temp;
    			}
    		}
    	}
    	return s;
    }
    
    public static boolean compare(StringTokenizer date1, StringTokenizer date2){
        date1.nextToken();date1.nextToken();
        String h = date1.nextToken();
        date2.nextToken();date2.nextToken();
        String k = date2.nextToken();
        if(h.compareTo(k)<0)
            return true;
        else return false;
    }
they are used simultaneously so it affects one another

this is the error:
Exception in thread "main" java.util.NoSuchElementException
at java.util.StringTokenizer.nextToken(StringTokenizer.java:332)

What seems to be the problem?
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 31 2005
Added on Mar 3 2005
19 comments
599 views