String应该有个split方法,可以把String转成String的数组public String[] split(String regex)Splits this string around matches of the given regular expression. This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array. The string "boo:and:foo", for example, yields the following results with these expressions: Regex Result : { "boo", "and", "foo" } o { "b", "", ":and:f" } Parameters: regex - the delimiting regular expression Returns: the array of strings computed by splitting this string around matches of the given regular expression
public class MyJava { public static void main( String args[] ) { String[] str= { "12", "34", "56", "78" }; int i = 0; for( i=0 ; i <= str.length - 1 ; i++) System.out.println( str[i] ); } }
大家搞明白lz的意思了吗?先要把字符串放到数组里,然后再输出。 下例供参考public class numTest { public static void main(String args[]) { String str = "aaa"; char [] strArr = str.toCharArray(); for(int i = 0;i<strArr.length;i++) {
System.out.println(Arrays.toString(strs));
String[] strs = { "abc", "panda", "cat", "123" };'};
for(String s:strs){
System.out.println(s);
}
public class Exe
{
public static void main(String args[])
{
String[] str= { "abc", "panda", "cat", "123" };
for(int i=0;i<str.length;i++)
{
System.out.println(str[i]);
}
}
}
This method works as if by invoking the two-argument split method with the given expression and a limit argument of zero. Trailing empty strings are therefore not included in the resulting array. The string "boo:and:foo", for example, yields the following results with these expressions: Regex Result
: { "boo", "and", "foo" }
o { "b", "", ":and:f" }
Parameters:
regex - the delimiting regular expression
Returns:
the array of strings computed by splitting this string around matches of the given regular expression
public static void main( String args[] ) { String[] str= { "12", "34", "56", "78" };
int i = 0;
for( i=0 ; i <= str.length - 1 ; i++)
System.out.println( str[i] );
}
}
下例供参考public class numTest {
public static void main(String args[]) {
String str = "aaa";
char [] strArr = str.toCharArray();
for(int i = 0;i<strArr.length;i++) {
System.out.println("output:" + strArr[i]);
}
}
}