Java Array Create toArrayElement(String s)

Here you can find the source of toArrayElement(String s)

Description

Takes a String s and returns a new String[1] with s as the only element.

License

Apache License

Parameter

Parameter Description
s The element to be wrapped

Return

String[]

Declaration

public static String[] toArrayElement(String s) 

Method Source Code

//package com.java2s;
//License from project: Apache License 

public class Main {
    /**/*from   w  w w  .  ja v a  2s .c  o  m*/
     * Takes a String s and returns a new String[1] with s as the only element.
     * If s is null or "", return String[0].
     *
     * @param s The element to be wrapped
     * @return String[]
     */
    public static String[] toArrayElement(String s) {
        return (s == null || s.length() == 0) ? new String[0] : new String[] { s };
    }
}

Related

  1. toArray(String text)
  2. toArray(T... items)
  3. toArray(T... items)
  4. toArrayClass(String className)
  5. toArrayDouble(final int[] array)
  6. toArrayLE(int val)