Professional Documents
Culture Documents
yash
b
YASH
String s1=Yash + 3+2; 4 objects are created (i) Yash (ii) 3 (iii)2 (iv)Yash32 S1=Yash32
Yash
Yash32
String s1=3+2+LD
Ans : s1=5LD String s1=3+2+LD+4+5; Ans : s1=5LD45
When u want string from other datatype u can use this method For eg:String s1=String.valueOf(12); s1=12; String s2=String.valueOf(12.2); s2=12.2 String s3=String.valueOf(true); s3=true
Equals takes into consideration the case While equalIgnoreCase does not take into consideration the case String s1=yash; String s2=Yash; If(s1.equals(s2)){ }
Objects cannot be compared with == Can be compared with equals method if that object overrides equals method of Object class Only two String literals can be compared with == but not String objects Program
For Sorting Purpose Returns < 0 if invoking string is less Returns > 0 if invoking string is more Returns == 0 if invoking string is equal to other String Apple.compareTo(Banana) <0 Banana.compareTo(Apple) >0 S1.compareTo(s2);
Boolean StartsWith(String str) Eg. FooBar.StartsWith(Foo) // returns true Boolean endsWith(Bar) Eg . FooBar.EndsWith(Bar) // returns true
CharAt(int location) For eg. S1=Hello; S1.CharAt(0) H S1.CharAt(4) o int Length() // for array obj it is attrib byte[ ] getBytes( ) indexOf(String str) subString(int startIndex,int EndIndex)
Trim() removes white space at the beginning and end of String toUpperCase()-converts all characters of String to uppercase
Can be changed .represents growable and rewritable string Important Methods:Int Length( ) Int Capacity() ensureCapacity(int)
StringBuilder vs StringBuffer Methods inside StringBuilder are not synchronized Everything else is same . Better to use StringBuilder as it works faster
Encapsulates runtime environment instance/obj cannot be directly created Use static(factory) method getRuntime() to get instance of RunTime class Control state and behaviour of JVM Applets cannot use it without raising security Exception
Process Exec(String path)- runs specified program Void gc() calls Garbage Collector Long freeMemory() returns free memory in JVM Long TotalMemory()-returns total memory in the system Exit (int status)-shuts down currently running JVM LoadLibrary(String Libname)
Methods:gc() SetSecurityManager(SecurityManager sm) SecurityManager getSecurityManager() Exit(int status) Properties getProperties() setErr(PrintStream p) setOut(PrintStream p) setIn(PrintStream p)
Program