aspose file tools*
The moose likes Beginning Java and the fly likes [newbie] how to work with java.lang.String.contains(..) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "[newbie] how to work with java.lang.String.contains(..)" Watch "[newbie] how to work with java.lang.String.contains(..)" New topic
Author

[newbie] how to work with java.lang.String.contains(..)

Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

I'm trying to get this code to read from a CharSequence structure, so that I can include it as a parameter for java.lang.String.contains(...), but I can't seem to figure out the syntax to use for declaring the variables. I'm aware that CharSequence is an interface, however a String doesn't cut it either.



Related links:
1. http://java.sun.com/javase/6/docs/api

Output
DEBUG :Salary()
DEBUG :Name()
DEBUG (1.1) - before checking for package name:public double homenetwork.bkr.training.Employee.Salary()
DEBUG (1.1) - before checking for package name:public java.util.Date homenetwork.bkr.training.Employee.HireDay()
DEBUG (1.1) - before checking for package name:public void homenetwork.bkr.training.Employee.raiseSalary(double)
DEBUG (1.1) - before checking for package name:public java.lang.Integer homenetwork.bkr.training.Employee.CountEmployees()
DEBUG (1.1) - before checking for package name:public boolean homenetwork.bkr.training.Employee.equals(homenetwork.bkr.training.Employee)
DEBUG (1.1) - before checking for package name:public java.lang.String homenetwork.bkr.training.Employee.Name()
DEBUG (1.1) - before checking for package name:public final void java.lang.Object.wait() throws java.lang.InterruptedException
DEBUG (1.1) - before checking for package name:public final void java.lang.Object.wait(long,int) throws java.lang.InterruptedException
DEBUG (1.1) - before checking for package name:public final native void java.lang.Object.wait(long) throws java.lang.InterruptedException
DEBUG (1.1) - before checking for package name:public native int java.lang.Object.hashCode()
DEBUG (1.1) - before checking for package name:public final native java.lang.Class java.lang.Object.getClass()
DEBUG (1.1) - before checking for package name:public boolean java.lang.Object.equals(java.lang.Object)
DEBUG (1.1) - before checking for package name:public java.lang.String java.lang.Object.toString()
DEBUG (1.1) - before checking for package name:public final native void java.lang.Object.notify()
DEBUG (1.1) - before checking for package name:public final native void java.lang.Object.notifyAll()

Jon
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38398
    
  23
I find it a bit difficult to work out what your actual problem is. Have you got a syntax problem? In which case your code would never compile.
Are you trying to get a String into a CharSequence? But a String already is a CharSequence. You don't need the toString() calls, nor the (CharSequence) casts. You appear to be getting the method names printed out.

Do you mean why are you not getting 1.3 and 1.4 printed? If you look very carefully at what follows your if(( . . .

By the way: Why are you starting all your identifiers with _?
Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

Campbell Ritchie wrote:

By the way: Why are you starting all your identifiers with _?
It's a C#/C++ convention for private variables (I forget which); I'm aware it's not commonly used in Java, I might have to grow out of it eventually, but it's kind of readable for now


Campbell Ritchie wrote:
Do you mean why are you not getting 1.3 and 1.4 printed? If you look very carefully at what follows your if(( . . .
I used that when troubleshooting the problem, now it's kind of useless


Well, to explain my problem:


Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38398
    
  23
I think you have solved your problem Well done
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38398
    
  23
I told you earlier. A String is a CharSequence. Look in the API documentation.
Jon Camilleri
Ranch Hand

Joined: Apr 25, 2008
Posts: 660

Campbell Ritchie wrote:I told you earlier. A String is a CharSequence. Look in the API documentation.


I know but what is wrong with the .contains then? Or my if statement?
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38398
    
  23
You said it yourself: it doesn't evaluate to true. I am sorry, but I thought you had got the solution there. Sorry for being premature about it.

You are testing whether your method name contains "homenetwork.bkr.training" AND "Salary()" AND "Name()" . . .
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: [newbie] how to work with java.lang.String.contains(..)