All pastes #948937 Raw Edit

Someone

public text v1 · immutable
·published 2008-03-19 14:59 UTC
rendered paste body
import java.util.*;

class ArrayListExample {

		String boat_name;

		/**
		* create an arraylist
		**/

		static ArrayList<String> AL = new ArrayList<String>();
		String[] boat_string_array;

		void addBoats(String boat_name) {
			this.boat_name = boat_name;
			// Add boats names (String) to the Array List
			AL.add(boat_name);
		}

		void getArrayListValues() {
				//Get the vlaue of the arraylist
				System.out.println(AL);
			}

		// You can convert the ArrayList to a regular StringArray like this..

		String[] convertToStringArray(ArrayList<String> AL) {
			this.AL = AL;
			boat_string_array = (String[]) AL.toArray(new String[AL.size()]);

			for(int i = 0; i < boat_string_array.length; i++)
			System.out.println("Boat Name: " + boat_string_array[i]);
			return boat_string_array;
}

	public static void main(String args[]) {
		ArrayListExample ALE = new ArrayListExample();

		ALE.addBoats("Mary Celest");
		ALE.addBoats("QE2");
		ALE.addBoats("Black Perl");
		ALE.addBoats("Titanic");

		ALE.getArrayListValues();

		ALE.convertToStringArray(AL);


		}
}