Translate an ArrayList to a Vector in Java

public static Vector<String> TranslateArrayListToVector(ArrayList<String> tempArray) {
	Vector<String> newArray = new Vector<String>();
	try {		
		for(String temp : tempArray) {
	} catch (Exception e) {
	}finally {
		return newArray;

Scoped Variables often return an ArrayList Object, which is a problem when you want to store the values easily enough into a NotesDocument Field.

This function allows the converting of an ArrayList to a Vector. In most cases this function can be used without modifications, although in some cases you might not using a String Object in the ArrayList or Vector.

e.g. If you want to return a value from a viewScope Variable (Holding an array of values from a Control) and save it into a NotesDocument:

doc.replaceItemValue("MultiValueField", TranslateArrayListToVector(viewScope.get("Values"));

UPDATE: Thanks to "Martin Rolph", "Jesse Gallagher", a simpler alternative to achieving this without having to apply my Snippet is the following:

doc.replaceItemValue("MultiValueField", new Vector<String>(viewScope.get("Values")));

John V Jardin
May 2, 2015 7:47 AM

All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.

2 comment(s)Login first to comment...
F van der Linden
(at 10:03 on 04.05.2015)
Another way is by using collections, w

Martin Rolph
(at 03:26 on 03.05.2015)
I think you can just do

doc.replaceItemValue("MultiValueField", new Vector(viewScope.get("Values")));

as a collection will accept another collection in the constructor