how to make substring a string in concern with length

hello frds,

i am in need of a very basic clarification.

i have a String like

String st="abcdefg";

String st1=st.substring(0,2);

String st2="ab"

i am getting st1="ab" like what need

but the when i compare st1 and st2 its not returning true (but it shows the same values while debugging)

its because the st1 object is contains length greater that st2.

i tried st1.trim() also

any help

thanks

[465 byte] By [LoveOpensourcea] at [2007-11-27 8:57:00]
# 1
Why don't you consult the API documentation for substring?
cotton.ma at 2007-7-12 21:20:54 > top of Java-index,Java Essentials,Java Programming...
# 2
i have gone through. but help less
LoveOpensourcea at 2007-7-12 21:20:54 > top of Java-index,Java Essentials,Java Programming...
# 3
I agree.
cotton.ma at 2007-7-12 21:20:54 > top of Java-index,Java Essentials,Java Programming...
# 4
> but the when i compare st1 and st2 its not returning> true (but it shows the same values while debugging)Let me guess. You aredoing something like this.System.out.println(st1 == st2);Use the equals() method to compare Strings, not ==.
CaptainMorgan08a at 2007-7-12 21:20:54 > top of Java-index,Java Essentials,Java Programming...
# 5
thanks .its done
LoveOpensourcea at 2007-7-12 21:20:54 > top of Java-index,Java Essentials,Java Programming...