[!INDEX]
- string constructor, string, buff, build, char[] z, byte[] d
- real codes for ct();
- why char is used for password storage ( char string ct()=string, char=object )
- syntax for class, boolean mt ( equals for object )
1. string constructor, string, buff, build, char[] z, byte[] d
public String (String s) {
}
public String (StringBuffer s) {
}
public String (StringBuilder s) {
}
public String (char[ ] c) {
}
public String (byte [ ] b) {
}
2. real codes for ct();
package package2;
public class Main1 {
public static void main(String[] args) {
String s2 = new String();
System.out.println("s2 : "+s2);//s2 :
String s3 = new String("raj");
System.out.println("s3 : "+s3);//s3 : raj
StringBuffer s4 = new StringBuffer("meerut");
String s5 = new String(s4); /* mutable - immutable*/
System.out.println("s5 : "+s5);//s5 : meerut
StringBuilder s6 = new StringBuilder("delhi");
String s7 = new String(s6);
System.out.println("s7 : "+s7); // s7 : delhi
byte [] b = {101,102,103};
String s8 = new String(b);
System.out.println("s8 : "+s8); //s8 : efg
char[] c = new char[]{'a','s','d','f'};
String s9 = new String(c);
System.out.println("s9 : "+s9); //s9 : asdf
}
}
3. why char is used for password storage ( char string ct()=string, char=object )
[!NOTE]
- password will save in scp and it is not applicable for garbage collection
- if print it will show
package package2;
public class Main1 {
public static void main(String[] args) {
/* char array - Character */
char [] c = {'a','b','c'};
String s = new String(c);//sop(s9) : abc
System.out.println("string1="+s);
char[] c1 = new char[]{'x','y','z'};
System.out.println("char="+c1); // print objects
String s1 = new String("xyz");
System.out.println("string2="+s1);
}
}
// string1=abc
// char=[C@7adf9f5f
// string2=xyz