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: Bug in Java ?? substring( int x, int y)

  1. #1
    Junior Member
    Join Date
    May 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Bug in Java ?? substring( int x, int y)

    Hi Guys,

    This simple code returns "Not Iqual" but should return "Iqual" the test is very simple str1 = "AAAA"; str2="AA"; str3=str1.substring(0,2)

    Printing:
    str1="AAAA"
    str2="AA"
    str3="AA"

    The comparison between str2 with str3 returns different. (Where is the error ? Or bug ??)

    I'm using Netbeans 7.3 and JDK 1.7.0.17

    Thanks

    Fallow Code


    public class String01 {
    public static void main(String[] args) {
    String str1 = "AAAA";
    String str2 = "AA";
    String str3 = str1.substring(1, 2);

    System.out.println(str1);
    System.out.println(str2);
    System.out.println(str3);

    if (str2 == str3) {
    System.out.println("Iqual");
    } else {
    System.out.println("Not Iqual");
    }
    }


  2. #2
    Junior Member
    Join Date
    May 2013
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Bug in Java ?? substring( int x, int y)

    u can use .equals operator to equal the two strings
    == operator not working properly in the case of string
    you write if(str2.equals(str3))

  3. #3
    Junior Member
    Join Date
    May 2013
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: Bug in Java ?? substring( int x, int y)

    thanks

Similar Threads

  1. [SOLVED] Java: Sorting int array in asc and desc
    By Abyd Ars in forum What's Wrong With My Code?
    Replies: 2
    Last Post: April 7th, 2013, 08:37 AM
  2. Java int comparison
    By maple1100 in forum What's Wrong With My Code?
    Replies: 9
    Last Post: March 3rd, 2013, 07:45 PM
  3. How to create an Int or double of what the user types int a JTextField?
    By Speedstack79 in forum Object Oriented Programming
    Replies: 2
    Last Post: January 13th, 2013, 11:00 PM
  4. List methods add(int k, Data data), set(int k, Data data), remove(int k)
    By Enirox in forum Object Oriented Programming
    Replies: 3
    Last Post: September 20th, 2012, 06:43 AM
  5. 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