wood burning stoves 2.0*
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 Android Security Essentials Live Lessons this week in the Android 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 />peter@panvox.net<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: http://aspose.com/file-tools
subject: Last Questiion for today I hope char.length
Similar Threads
String to char.
About what Console.readPassword() returns...
+= or =+
Primitive return type in java
retain apostrophe in Collection object