• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()
 
Campbell Ritchie
Sheriff
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 664
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you have solved your problem Well done
 
Campbell Ritchie
Sheriff
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I told you earlier. A String is a CharSequence. Look in the API documentation.
 
Jon Camilleri
Ranch Hand
Posts: 664
Chrome Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 49367
62
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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()" . . .
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic