»
 

Go Back   ResellerRatings Store Ratings > ResellerRatings Forums > Tech Support

Reply
 
LinkBack Thread Tools Display Modes
Old 02-11-2004, 09:24 AM   #1 (permalink)
Registered User
 
Join Date: Mar 2002
Posts: 18
weezal100 is on a distinguished road
Kids Help understanding some java!

Hi,
I am learning java and am trying to understand some code that is written in Java 1.5, although I am more used to Java 1.4.2.
Could someone please convert this to java 1.4.2 or instead just tell me what is going on in the code?
thanks it is much appreciated

Code:
import java.util.*;

class Match {
	private String sentence;
	private List words = new ArrayList();
	private Sentence sent

// some code removed...
// important part below... (in java 1.5)

	public boolean checking(int c) 
	{
	System.out.print("invoke the check(%d)\n", c);
		if(c > (sentence.length()-1))
	{
		return true;
	}
	for (String s : words)
		{
		if(sentence.substring(c, sentence.length()).startsWith(s))
		{
			sent.addBoundary(c);
			if(check(c+s.length()))
			{
	// System.out.printf("setting the boundary at %d\n", c); 
				return true;
			}
			sent.delBoundary();
		}
	}
		return false;
}
(note:there is another class called sentence that also exist)

weezal100 is offline   Reply With Quote
Old 02-12-2004, 04:42 PM   #2 (permalink)
Registered User
 
Join Date: Feb 2004
Posts: 1
gklue is on a distinguished road
From Sun's web site (re: for (String s : words)):

Enhanced for loop
The Iterator class is used heavily by the Collections API. It provides the mechanism to navigate sequentially through a Collection. The new enhanced for loop can replace the iterator when simply traversing through a Collection as follows. The compiler generates the looping code necessary and with generic types no additional casting is required.

Before

ArrayList<Integer> list = new ArrayList<Integer>();
for (Iterator i = list.iterator(); i.hasNext();) {
Integer value=(Integer)i.next();
}




After

ArrayList<Integer> list = new ArrayList<Integer>();
for (Integer i : list) { ... }
gklue is offline   Reply With Quote
Reply




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Most Active Discussions

Recent Discussions

All times are GMT -6. The time now is 10:51 AM.