1 4 5 9 10 package examples; 11 12 import java.util.List ; 13 import java.util.Vector ; 14 import java.util.Map ; 15 import java.util.HashMap ; 16 17 public class ReturnTypeExample { 18 19 public static int returnInteger() { 20 return 1; 21 } 22 23 public static Integer returnIntegerObject() { 24 return new Integer (2); 25 } 26 27 public static short returnShort() { 28 return 3; 29 } 30 31 public static Short returnShortObject() { 32 return new Short ((short)4); 33 } 34 35 public static long returnLong() { 36 return 5; 37 } 38 39 public static Long returnLongObject() { 40 return new Long (6); 41 } 42 43 public static float returnFloat() { 44 return 7; 45 } 46 47 public static Float returnFloatObject() { 48 return new Float (8); 49 } 50 51 public static double returnDouble() { 52 return 3.14159; 53 } 54 55 public static Double returnDoubleObject() { 56 return new Double (3.14159); 57 } 58 59 public static byte returnByte() { 60 return (byte)11; 61 } 62 63 public static Byte returnByteObject() { 64 return new Byte ((byte)12); 65 } 66 67 public static boolean returnBoolean() { 68 return true; 69 } 70 71 public static Boolean returnBooleanObject() { 72 return new Boolean (false); 73 } 74 75 public static char returnCharacter() { 76 return 'a'; 77 } 78 79 public static Character returnCharacterObject() { 80 return new Character ('b'); 81 } 82 83 public static String returnString() { 84 return "returing a string"; 85 } 86 87 public static Coordinate returnCoordinateObject() { 88 return new Coordinate(4,2); 89 } 90 91 public static int[] returnIntegerArray() { 92 int[] intarr = { 1, 2, 3, 4, 5 }; 93 return intarr; 94 } 95 96 public static String [] returnStringArray() { 97 String [] strarr = { "one", "two", "three", "four", "five" }; 98 return strarr; 99 } 100 101 public static Coordinate[] returnCoordinateObjectArray() { 102 Coordinate[] coarr = { new Coordinate(1,1), 103 new Coordinate(2,2), 104 new Coordinate(3,3), 105 new Coordinate(4,4), 106 new Coordinate(5,5) }; 107 return coarr; 108 } 109 110 public static List returnIntegerList() { 111 List list = new Vector (); 112 list.add(new Integer (1)); 113 list.add(new Integer (2)); 114 list.add(new Integer (3)); 115 list.add(new Integer (4)); 116 list.add(new Integer (5)); 117 return list; 118 } 119 120 public static Map returnIntegerMap() { 121 Map map = new HashMap (); 122 map.put("one", new Integer (1)); 123 map.put("two", new Integer (2)); 124 map.put("three", new Integer (3)); 125 map.put("four", new Integer (4)); 126 map.put("five", new Integer (5)); 127 return map; 128 } 129 130 public static List returnCoordinateObjectList() { 131 List list = new Vector (); 132 list.add(new Coordinate(1,1)); 133 list.add(new Coordinate(2,2)); 134 list.add(new Coordinate(3,3)); 135 list.add(new Coordinate(4,4)); 136 list.add(new Coordinate(5,5)); 137 return list; 138 } 139 140 public static Map returnCoordinateObjectMap() { 141 Map map = new HashMap (); 142 map.put("one", new Coordinate(1,1)); 143 map.put("two", new Coordinate(2,3)); 144 map.put("three", new Coordinate(5,8)); 145 map.put("four", new Coordinate(13,21)); 146 map.put("five", new Coordinate(34,55)); 147 return map; 148 } 149 150 static public class Coordinate { 151 public int x; 152 public int y; 153 154 public Coordinate(int x, int y) { 155 this.x = x; 156 this.y = y; 157 } 158 159 public String toString() { 160 return "x: " + this.x + ", y: " + this.y; 161 } 162 } 163 164 } 165 | Popular Tags |