| java.lang.Object util.ArrayUtil
ArrayUtil | public class ArrayUtil (Code) | | contains static methods that operate on arrays or return arrays.
author: Rahul Kumar June 2001. author: $Author: rahul_kumar $ $Id: ArrayUtil.java,v 1.1 2004/01/01 06:49:54 rahul_kumar Exp rahul $ |
Method Summary | |
public static String[] | appendString(String[] sarr, String text) | public static Object | elementAt(Object a, int index) identical to get (for those used to ArrayList class methods). | public static String[] | enclose(String[] sarr, String before, String after) enclose each element in an array with given strings. | public static String | enclose(String sarr, String before, String after) | public static Object | get(Object a, int index) returns the value at an index, a negative index denotes
indexes taken from end backwards (-1 means last but one),
An index higher than array size returns highest element,
A negative index larger than size will return element at 0. | public static int | indexOf(Object a, Object key) sequential search of array returning index if found, else -1.
Return values start from 0. | public static int | indexOf(int a, int key) | public static int | indexOfEndsWith(String a, String key) searches an array of Strings that ends with the given key
returning its index.
e.g. | public static int | indexOfEndsWith(String key, String a) checks whether the key, ends with a string in the array given.
This is a reverse of the above, returning its index.
e.g. | public static int | indexOfIndexOf(String a, String key) searches an array of Strings that includes the given key
returning its index. | public static int | indexOfRegex(String s, String pattern) find a regex in the array and return its index, else -1. | public static int | indexOfStartsWith(String a, String key) searches an array of a String that starts with the given key
returning its index. | public static String | join(String[] sarr, char csep) joins values of a string array with the given separator
into a string and returns the string. | public static String | join(Object[] sarr, char csep) | public static String | join(List sarr, char csep) joins an arraylist. | public static String[] | prependString(String[] sarr, String text) | public static List | prependString(List sarr, String text) | public static String[] | split(String st, char sep) splits a given string on given character separator returning
an array of strings. | public static String[] | split(String st, String ssep) | public static Object[] | toArray(Enumeration e) for those bad days when you have to deal with an enumeration and you
sorely need to treat is as an array or Collection. | public static Object[] | toArray(Enumeration e, Object[] a) If you want to put the value into an array of some particular
type, pass that as a parameter. | public static Object[] | toSortedArray(Enumeration e) | public static Object[] | toSortedArray(Enumeration e, Object[] a) If you want to put the value into an array of some particular
type, pass that as a parameter. | public static String[] | toStringArray(List l) | public static String[] | trim(String[] sarr) remove zero length entries from the given array - principally created for
string arrays coming from JSP's. |
appendString | public static String[] appendString(String[] sarr, String text)(Code) | | append a string to each element in an array
|
elementAt | public static Object elementAt(Object a, int index)(Code) | | identical to get (for those used to ArrayList class methods).
|
enclose | public static String[] enclose(String[] sarr, String before, String after)(Code) | | enclose each element in an array with given strings.
Useful when surrounding a string with tags
|
get | public static Object get(Object a, int index)(Code) | | returns the value at an index, a negative index denotes
indexes taken from end backwards (-1 means last but one),
An index higher than array size returns highest element,
A negative index larger than size will return element at 0.
|
indexOf | public static int indexOf(Object a, Object key)(Code) | | sequential search of array returning index if found, else -1.
Return values start from 0.
For repeated searches on a large array, please use Arrays.sort() once
and then use binarySearch. However, that would work only if index
does not matter.
|
indexOf | public static int indexOf(int a, int key)(Code) | | |
indexOfEndsWith | public static int indexOfEndsWith(String a, String key)(Code) | | searches an array of Strings that ends with the given key
returning its index.
e.g. EMPID, ['MGREMPID','NAME']
|
indexOfEndsWith | public static int indexOfEndsWith(String key, String a)(Code) | | checks whether the key, ends with a string in the array given.
This is a reverse of the above, returning its index.
e.g. MGREMPID, ['EMPID','NAME']
RK added on 20031226 20:54:41
|
indexOfIndexOf | public static int indexOfIndexOf(String a, String key)(Code) | | searches an array of Strings that includes the given key
returning its index.
|
indexOfRegex | public static int indexOfRegex(String s, String pattern)(Code) | | find a regex in the array and return its index, else -1.
pattern should be enclosed in // with possible modifiers at end
e.g. /pattern/ OR /pattern/i .
|
indexOfStartsWith | public static int indexOfStartsWith(String a, String key)(Code) | | searches an array of a String that starts with the given key
returning its index.
|
join | public static String join(String[] sarr, char csep)(Code) | | joins values of a string array with the given separator
into a string and returns the string.
Does not delimit the last value, obviously.
|
join | public static String join(List sarr, char csep)(Code) | | joins an arraylist. this should go into a new ListUtil
|
prependString | public static String[] prependString(String[] sarr, String text)(Code) | | prepend a string to each element in an array
|
split | public static String[] split(String st, char sep)(Code) | | splits a given string on given character separator returning
an array of strings.
THis would be more efficient than using string tokenizer which
takes a String not char as argument.
author: Rahul Kumar June 17, 2001 author: How to deal with consecutive delimiters - i am returning blank author: strings. |
split | public static String[] split(String st, String ssep)(Code) | | THIS WONT WORK AS EXPECTED SINCE ssep actually means each
character in ssep is a delim
|
toArray | public static Object[] toArray(Enumeration e)(Code) | | for those bad days when you have to deal with an enumeration and you
sorely need to treat is as an array or Collection.
|
toArray | public static Object[] toArray(Enumeration e, Object[] a)(Code) | | If you want to put the value into an array of some particular
type, pass that as a parameter. On the lines of ArrayList.toArray(Object[])
|
toSortedArray | public static Object[] toSortedArray(Enumeration e, Object[] a)(Code) | | If you want to put the value into an array of some particular
type, pass that as a parameter. On the lines of ArrayList.toArray(Object[])
|
trim | public static String[] trim(String[] sarr)(Code) | | remove zero length entries from the given array - principally created for
string arrays coming from JSP's. For other rare cases, i am also trimming the string
and then checking its length.
|
|
|