Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 3 of 3

Thread: Operator || cannot be applied to java.lang.String, boolean

  1. #1
    Member
    Join Date
    Oct 2011
    Posts
    114
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Operator || cannot be applied to java.lang.String, boolean

    Copied out of my Lewis and Loftus book.

    code section:

       private static boolean beginsWithBlend(String word) {
     
            return (word.startsWith("bl" || word.startsWith("sc")
                    || word.startsWith("br") || word.startsWith("sh")
                    || word.startsWith("ch") || word.startsWith("sh")
                    || word.startsWith("cl") || word.startsWith("sk")
                    || word.startsWith("cr") || word.startsWith("sl")
                    || word.startsWith("dr") || word.startsWith("sn")
                    || word.startsWith("dw") || word.startsWith("sm")
                    || word.startsWith("fl") || word.startsWith("sp")
                    || word.startsWith("fr") || word.startsWith("sq")
                    || word.startsWith("gl") || word.startsWith("st")
                    || word.startsWith("gr") || word.startsWith("sw")
                    || word.startsWith("kl") || word.startsWith("th")
                    || word.startsWith("ph") || word.startsWith("tr")
                    || word.startsWith("pl") || word.startsWith("wh")
                    || word.startsWith("pr") || word.startsWith("wr"));
        }

    the whole return statement is red underlined and when i highlight over the red 'i' which indicates the error it is:

    cannot find symbol symbol: method starts with(boolean)
    Operator || cannot be applied to java.lang.String, boolean


    As i said its straight out of my textbook, yet netbeans is saying the || operator cannot be applied in a boolean?
    Last edited by djl1990; October 25th, 2011 at 05:10 PM.


  2. #2
    Member Staticity's Avatar
    Join Date
    Jul 2011
    Location
    Texas
    Posts
    105
    My Mood
    Inspired
    Thanks
    3
    Thanked 5 Times in 5 Posts

    Default Re: Operator || cannot be applied to java.lang.String, boolean

    Quote Originally Posted by djl1990 View Post

    [CODE]
    return (word.startsWith("bl" || word.startsWith("sc")
    || word.startsWith("br") || word.startsWith("sh")
    || word.startsWith("ch") || word.startsWith("sh")
    Look at this portion of your code.. I'll let you notice your mistake.
    Simplicity calls for Complexity. Think about it.

  3. #3
    Member
    Join Date
    Oct 2011
    Posts
    114
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Re: Operator || cannot be applied to java.lang.String, boolean

    ive spotted it thanks

Similar Threads

  1. Java Error cannot be applied to (java.lang.String), phone book entry program.
    By iceyferrara in forum What's Wrong With My Code?
    Replies: 5
    Last Post: September 23rd, 2011, 06:32 AM
  2. Operator % cannot be applied to java.lang.String,int?
    By javarum in forum Java Theory & Questions
    Replies: 8
    Last Post: July 12th, 2011, 08:06 PM
  3. Replies: 2
    Last Post: November 3rd, 2009, 06:28 AM
  4. How to reverse a String using java.lang.StringBuilder
    By JavaPF in forum Java Code Snippets and Tutorials
    Replies: 0
    Last Post: July 22nd, 2009, 09:42 AM
  5. [SOLVED] Facing java error "cannot be applied to (java.lang.String)"
    By tazjaime in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 23rd, 2009, 10:19 AM