Results 1 to 6 of 6
Like Tree1Likes
  • 1 Post By jim829

Thread: how to check CharSequence

  1. #1
    009
    009 is offline Member
    Join Date
    May 2014
    Posts
    22
    Rep Power
    0

    Default how to check CharSequence

    hi i what to chaeck if value is not equal to CharSequence value

    i try this but geting error
    Java Code:
     private CharSequence testvalue = "";
    
    if (!isEqualTo("BCDEF".contains(testvalue))){
    }
    
    public boolean isEqualTo(String s_src, String s_compareTo)
        {
    
            boolean flag = false;
            try
            {
                if (s_src.toUpperCase().trim().equals(s_compareTo.toUpperCase().trim()))
                {
                    flag = true;
                }
            } catch (NullPointerException npe)
            {
                logger.log(Level.FATAL, npe.getMessage(), npe);
                return false;
            }
    
            return flag;
        }

  2. #2
    Tolls is offline Moderator
    Join Date
    Apr 2009
    Posts
    12,097
    Rep Power
    20

    Default Re: how to check CharSequence

    What error are you getting?
    Please do not ask for code as refusal often offends.

    ** This space for rent **

  3. #3
    RamyaSivakanth's Avatar
    RamyaSivakanth is offline Senior Member
    Join Date
    Apr 2009
    Location
    Chennai
    Posts
    842
    Rep Power
    6

    Default Re: how to check CharSequence

    isEqualTo method is correct ...But how u are calling the above if condition ????? if (!isEqualTo("BCDEF".contains(testvalue))){
    }
    u will get compilation error..and why u need Nullpointer exception..u can check null condition right?
    Ramya:cool:

  4. #4
    pbj
    pbj is offline Member
    Join Date
    Jun 2014
    Posts
    15
    Rep Power
    0

    Default Re: how to check CharSequence

    009,
    I am confused as to why you would have to write your own methods for something that can be found within the standard Java libraries. You would just have to chain a few methods together, to be more specific; convert your CharSequence to a string via .toString() and if you don't care about case use .equalsIgnoreCase() with your comparison string as a parameter.
    Java Code:
    package sample;
    
    class CharSequenceComparison {
    	public static void main(String[] args) {
    		CharSequence testValue = "test";
    		
    		if (testValue.toString().equals("test"))
    			System.out.println("equal");
    		else
    			System.out.println("not equal");
    	}
    }
    If you have any questions, feel free to respond.

  5. #5
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    3,785
    Rep Power
    5

    Default Re: how to check CharSequence

    Quote Originally Posted by pbj View Post
    I am confused as to why you would have to write your own methods for something that can be found within the standard Java libraries.
    A lot of students need to learn how to implement various algorithms themselves. They won't learn how to implement a quick sort, insertion sort, linked list, or any other pertinent computer science algorithm by relying on the JDK libraries.

    Regards,
    Jim
    Last edited by jim829; 06-12-2014 at 11:50 PM.
    Norm likes this.
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

  6. #6
    pbj
    pbj is offline Member
    Join Date
    Jun 2014
    Posts
    15
    Rep Power
    0

    Default Re: how to check CharSequence

    Jim,
    I understand that, but without going into my opinion of the education system; I appreciate your feedback though.

Similar Threads

  1. Replies: 14
    Last Post: 03-28-2014, 09:46 AM
  2. check this out
    By RajeshReddy in forum New To Java
    Replies: 10
    Last Post: 07-25-2011, 12:28 PM
  3. Can someone check this over?
    By Phyxed in forum New To Java
    Replies: 2
    Last Post: 03-29-2011, 09:07 AM
  4. Check box tag
    By elizaabru in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 08-26-2008, 02:37 PM
  5. [SOLVED] CharSequence interface
    By Nicholas Jordan in forum Advanced Java
    Replies: 11
    Last Post: 07-11-2008, 08:49 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •