My Java Tutorials - Casting
Static Methods:
Static methods are methods that are throughout the whole class,
not just an instance.
Below you see the different ways in which protected static methods,
private static methods
and public static methods are accessed. Note that you can never use
the keyword "this"
with a static variable.
For Example...
Getting a String out of an ArrayList
String StringName = (String)arrayListName.get(n);
Getting a double out of an ArrayList (Stored in the ArrayList as a Double)
double doubName = ((Double)arrayListName.get(n)).doubleValue();
Getting a String out of a Vector
String StringName = (String)vectName.get(n);
Getting a double out of a Vector (Stored in the Vector as a Double)
double doubName = ((Double)vectName.get(n)).doubleValue();
String to Double to double (using Double constructor)
double doubName = new Double(stringName).doubleValue;
String to Double to double
double doubName = Double.valueOf(stringName).doubleValue;
String to double (using static Double method - Java 1.2 & later)
double doubName = Double.parseDouble(stringName);
double to a new String (using the String constructor)
String stringName = new String(doubleName);
double to existing String
stringName = String.valueOf(doubleName);
double to int
double doubleName = 3;
int intName = (int)doubleName;
String to char
char charName = stringName.charAt(2); //must specify offset in string to get char from