This week's book giveaway is in the Jobs Discussion forum.
We're giving away four copies of Soft Skills and have John Sonmez on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes Last Questiion for today I hope char.length Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Last Questiion for today I hope char.length" Watch "Last Questiion for today I hope char.length" New topic

Last Questiion for today I hope char.length

Anthony Smith
Ranch Hand

Joined: Sep 10, 2001
Posts: 285
public static boolean is_special(char value)

char[] special_chars = {'#', '$', '%', '&', '*', '.', ','};

for (int i = 0; i!=special_chars.length(); i++)
if (value==special_chars[i])
return true;
return false;

I dont think it likes this line
Manfred Leonhardt
Ranch Hand

Joined: Jan 09, 2001
Posts: 1492
Hi Anthony,
You are correct. The method length is not defined for arrays. It is defined for String however:
String s = "Yesterday";
int i = s.length(); // Equals 9.
You want the field length that is defined for arrays:
String[] as = {"Yesterday", "Today", "Tommorrow"};
int i = as.length; // Equals 3.
Peter Simard
Ranch Hand

Joined: Oct 31, 2001
Posts: 54
length is a property of Arrays, so you could use spec_char.length

PAS<br /><br />2b || !2b
Colin Kenworthy
Ranch Hand

Joined: Aug 06, 2001
Posts: 88
Yes, length is not a method but a property of arrays so you just need to drop the '()'.
I agree. Here's the link:
subject: Last Questiion for today I hope char.length