split
package com.equal_;
import java.sql.SQLException;
public class Cast {
public static void main(String[] args) throws SQLException{
String s="ABCD";
String[] ss=s.split("");
for(String value:ss){
System.out.print(value+"\t");
}
}
}
iteration
package com.equal_;
import java.sql.SQLException;
public class Cast {
public static void main(String[] args) throws SQLException{
String s="ABCD";
String[] ss=new String[s.length()];
for(int i=0;i<ss.length;++i){
ss[i]=s.charAt(i)+"";
}
for(String value:ss) System.out.print(value+"\t");
char[] c=new char[s.length()];
for(int i=0;i<c.length;++i){
c[i]=s.charAt(i);
}
for(char value:c) System.out.println(value);
}
}
@Override
public boolean equals(Object obj) {
if (this == obj) return true;
if (obj instanceof String) {
String str = (String) obj;
if (str.length() == this.length()) {
int i = 0;
int n = this.length();
while (n-- != 0) {
if (str.charAt(i) != this.charAt(i)) return false;
}
}
}
return false; // obj is not String
}
Java 拆分String String equals 方法的实现
原文:https://www.cnblogs.com/dissipate/p/14959917.html