String to Int
String myString = "1234";
int foo = Integer.parseInt(myString);
Declare Arry
For primitive types:
int[] myIntArray = new int[3];
int[] myIntArray = {1,2,3};
int[] myIntArray = new int[]{1,2,3};
For classes, for example
String
, it's the same:String[] myStringArray = new String[3];
String[] myStringArray = {"a","b","c"};
String[] myStringArray = new String[]{"a","b","c"};
The third way of initializing is useful when you declare the array first and then initialize it. The cast is necessary here.
String[] myStringArray;
myStringArray = new String[]{"a","b","c"};
For-eachfor (char ch: "xyz".toCharArray()) {
}
ListList<String> someList = new ArrayList<String>();
Get String character by indexString text = "foo";
char a_char = text.charAt(0);
System.out.println(a_char); // Prints f
Character to StringCharacter.toString("C")
No comments:
Post a Comment