File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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 EJB 3 in Action this week in the EJB and other Java EE Technologies 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
Author

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
special_chars.length()
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.
Regards,
Manfred.
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
About what Console.readPassword() returns...
+= or =+
String to char.
retain apostrophe in Collection object
Primitive return type in java