Here you can find the source of toStringArray(Iterator
String
objects, containing the elements of a supplied Iterator
.
Parameter | Description |
---|---|
iterator | The iterator containing the elements to create the array with. |
String
array.
public static String[] toStringArray(Iterator<String> iterator)
//package com.java2s; /*// w w w . j a v a 2 s .com * Copyright 2001-2013 Geert Bevin (gbevin[remove] at uwyn dot com) * Licensed under the Apache License, Version 2.0 (the "License") */ import java.util.*; public class Main { /** * Creates a new array of <code>String</code> objects, containing the * elements of a supplied <code>Iterator</code>. * * @param iterator The iterator containing the elements to create the * array with. * @return The new <code>String</code> array. * @since 1.0 */ public static String[] toStringArray(Iterator<String> iterator) { if (null == iterator) { return new String[0]; } ArrayList<String> strings = new ArrayList<>(); while (iterator.hasNext()) { strings.add(iterator.next()); } String[] string_array = new String[strings.size()]; strings.toArray(string_array); return string_array; } }