• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 664
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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()
 
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think you have solved your problem Well done
 
Campbell Ritchie
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Eclipse IDE Chrome
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Marshal
Posts: 79178
377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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()" . . .
reply
    Bookmark Topic Watch Topic
  • New Topic