com.javaranch.common
Class Structures

java.lang.Object
  |
  +--com.javaranch.common.Structures

public class Structures
extends java.lang.Object

A collection of static methods related to data structures.

- - - - - - - - - - - - - - - - -

Copyright (c) 1998-2004 Paul Wheaton

You are welcome to do whatever you want to with this source file provided that you maintain this comment fragment (between the dashed lines). Modify it, change the package name, change the class name ... personal or business use ... sell it, share it ... add a copyright for the portions you add ...

My goal in giving this away and maintaining the copyright is to hopefully direct developers back to JavaRanch.

The original source can be found at JavaRanch

- - - - - - - - - - - - - - - - -

Author:
Paul Wheaton


Method Summary
static java.lang.String arrayToString(java.lang.String[] text)
           
static java.lang.String[] listToStringArray(java.util.List list)
           
static java.lang.String setToString(java.util.Set set)
          Given a set, return a string with a newline between each object's toString() results.
static java.lang.String[] stringToArray(java.lang.String text)
           
static java.util.Set stringToSet(java.lang.String text)
          Given a space or newline delimited string, inner strings will be extracted and moved to a Set.
static byte[] subArray(byte[] b, int index, int length)
          Get a sub array from a byte array.
static java.lang.Object[] subArray(java.lang.Object[] obj, int index, int length)
          Get a shallow sub array from an object array.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

subArray

public static byte[] subArray(byte[] b,
                              int index,
                              int length)
Get a sub array from a byte array.

Parameters:
b - The original array. It will not be modified.

index - Where the new array is to be copied from. If index is 0, the very first byte from b will be included. If first is beyond the last byte in b, this method will return null.

length - The number of bytes to be copied. If there are fewer than length bytes left, how ever many are left will be returned.

Returns:
A new byte array or null if index is greater than the last element of b.


subArray

public static java.lang.Object[] subArray(java.lang.Object[] obj,
                                          int index,
                                          int length)
Get a shallow sub array from an object array.

Parameters:
obj - The original array. It will not be modified.

index - Where the new array is to be copied from. If index is 0, the very first object reference from obj will be included. If first is beyond the last object reference in obj, this method will return null.

length - The number of object references to be copied. If there are fewer than length references left, how ever many are left will be returned.

Returns:
A new object array or null if index is greater than the last element of obj.


stringToArray

public static java.lang.String[] stringToArray(java.lang.String text)

arrayToString

public static java.lang.String arrayToString(java.lang.String[] text)

setToString

public static java.lang.String setToString(java.util.Set set)
Given a set, return a string with a newline between each object's toString() results.


stringToSet

public static java.util.Set stringToSet(java.lang.String text)
Given a space or newline delimited string, inner strings will be extracted and moved to a Set.


listToStringArray

public static java.lang.String[] listToStringArray(java.util.List list)


Copyright ©2004 Paul Wheaton All Rights Reserved