StringArray Chilkat2 Java Reference Documentation
StringArray
Current Version: 11.7.0
Markdown version of this page for AI tools (v 11.7.0) · all AI docs
Chilkat.StringArray
Store strings in an internal ordered collection and retrieve them by
zero-based index using
Append, prepend, insert, replace, remove, clear, or pop strings as the
collection changes.
Load one string per line from files or text, and save the collection back
to files or a single line-delimited string.
Use charset-specific load and save methods when working with UTF-8,
UTF-16, or other non-ANSI text encodings.
Check for exact strings, find values from a starting index, match
wildcard patterns, and sort ascending or descending.
Serialize the collection for later restoration, split text into entries,
and combine or subtract collections with set-style operations.
Manage an ordered collection of strings, with StringTable recommended for new code.
Chilkat.StringArray is an ordered string-collection class that
can append, prepend, insert, replace, remove, pop, and retrieve strings by
index. It can load one string per line from files or in-memory text, save the
collection back to text or files, enforce uniqueness, trim incoming values,
normalize line endings, search by exact value or wildcard pattern, sort
entries, split text into entries, serialize and restore the collection, and
perform set-style operations such as union and subtraction.
Chilkat.StringTable instead of
Chilkat.StringArray. StringTable provides a simpler,
faster, and more memory-efficient way to manage ordered lists of strings.
Use StringArray primarily when maintaining existing code or when
a specific API or older example already uses it.
Ordered string collection
GetString, StrAt, or
LastString.
Add and modify entries
Load and save text
Charset-aware file I/O
Search, match, and sort
Serialize and combine
StringArray, optionally set Trim,
Crlf, or Unique, then append strings directly or
load them from a file or text block. Search, sort, split, remove, union, or
subtract entries as needed, then save the result with
SaveToText, SaveToFile, or
SaveToFile2. For new code that only needs an ordered list of
strings, use Chilkat.StringTable instead.
Array,
Chilkat.StringArray is a Chilkat object that manages an ordered
string collection. It should not be confused with a native array type in a
programming language.
Object Creation
import com.chilkatsoft.chilkat2.ChilkatException;
import com.chilkatsoft.chilkat2.StringArray;
try (StringArray stringArray = new StringArray()) {
// ... use stringArray ...
} catch (ChilkatException e) {
System.out.println(e.getMessage()); // "StringArray.someMethod failed: <reason>"
System.out.println(e.getLastErrorText()); // the full log of the failed call
}Creates the underlying native Chilkat object. The native library (chilkat2java) is loaded the first time any Chilkat2 object is created; see the README in the download for where it is looked for (-Dchilkat2.library.path, a classpath resource, or java.library.path).
Releases the native object (StringArray is AutoCloseable, so try-with-resources calls it). Calling it again does nothing; any other method or property accessor called afterwards throws IllegalStateException. An object that is never closed is freed by a background cleaner once it becomes unreachable, but the garbage collector does not see native memory, so closing is the normal path. Objects returned by methods are owned by the caller too.
Returns true once close() has been called.
Errors
A method that fails throws ChilkatException, an unchecked exception carrying getClassName(), getMethodName(), getReason() (one line, also in the message) and getLastErrorText() (the full log, captured at the moment of the failure). The object remains usable. Methods that look something up and find nothing return null instead of throwing (each such method says so), and methods that answer a question (hasMember, isUnlocked, ...) return a plain boolean. Property accessors do not throw for Chilkat reasons.
A null string or object argument throws NullPointerException naming the parameter (except where a method documents that null is accepted), and a string containing U+0000 throws IllegalArgumentException.
Use an object from one thread at a time; it may be handed from one thread to another. The one cross-thread operation is setting setAbortCurrent(true) on an object that is busy in another thread (on the classes that have AbortCurrent). Unlocking: call new Global().unlockBundle("...") once at startup.
Properties
Count
int getCount()
The number of strings contained within the object's internal array (i.e. ordered collection).
Important: This is an object that contains a collection of strings. Although the class/object name includes the word Array, it should not be confused with an array in the sense of the primitive array type used in a given programming language.
Crlf
boolean getCrlf()
void setCrlf(boolean value)
If true, strings are always automatically converted to use CRLF line endings. If false, strings are automatically converted to use bare LF line endings.
DebugLogFilePath
String getDebugLogFilePath()
void setDebugLogFilePath(String value)
If set to a file path, this property logs the LastErrorText of each Chilkat method or property call to the specified file. This logging helps identify the context and history of Chilkat calls leading up to any crash or hang, aiding in debugging.
Enabling the VerboseLogging property provides more detailed information. This property is mainly used for debugging rare instances where a Chilkat method call causes a hang or crash, which should generally not happen.
Possible causes of hangs include:
- A timeout property set to 0, indicating an infinite timeout.
- A hang occurring within an event callback in the application code.
- An internal bug in the Chilkat code causing the hang.
LastErrorHtml
String getLastErrorHtml()
Provides HTML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastErrorText
String getLastErrorText()
Provides plain text information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
LastErrorXml
String getLastErrorXml()
Provides XML-formatted information about the last called method or property. If a method call fails or behaves unexpectedly, check this property for details. Note that information is available regardless of the method call's success.
topLastMethodSuccess
boolean getLastMethodSuccess()
void setLastMethodSuccess(boolean value)
Indicates the success or failure of the most recent method call: true means success, false means failure. This property remains unchanged by property setters or getters. This method is present to address challenges in checking for null or Nothing returns in certain programming languages. Note: This property does not apply to methods that return integer values or to boolean-returning methods where the boolean does not indicate success or failure.
Length
int getLength()
The number of strings contained within the internal collection. (Identical to the Count property.)
topTrim
boolean getTrim()
void setTrim(boolean value)
If true, whitespace, including carriage-returns and linefeeds, are automatically removed from the beginning and end of a string when added to the collection.
Unique
boolean getUnique()
void setUnique(boolean value)
If true, then duplicates are not allowed. When an attempt is made to insert a string that already exists, the duplicate insertion is silently suppressed and no error is returned. The default value is false.
VerboseLogging
boolean getVerboseLogging()
void setVerboseLogging(boolean value)
If set to true, then the contents of LastErrorText (or LastErrorXml, or LastErrorHtml) may contain more verbose information. The default value is false. Verbose logging should only be used for debugging. The potentially large quantity of logged information may adversely affect peformance.
Version
String getVersion()
Methods
Append
Appends a string to the end of the internal ordered collection.
Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
AppendSerialized
Appends multiple strings to the end of the internal ordered collection. The encodedStr is what is returned from the Serialize method (see below).
Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
Clear
Remove all strings from the internal collection.
topContains
Returns true if the string is present in the internal collection. The string comparisons are case sensitive.
Never throws: false is an answer, not a failure.
Find
Finds the index of the first string equal to findStr. The search begins at startIndex. If the string is not found, -1 is returned. The first string in the array is at index 0.
FindFirstMatch
Finds the first string that matches the matchPattern. The search begins at startIndex. If the string is not found, -1 is returned. The first string in the array is at index 0.
The matchPattern may contain zero or more asterisk chars, each of which matches 0 or more of any character.
GetString
Returns the string at an indexed location within the internal collection. The first string is located at index 0.
Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
GetStringLen
Returns Nth string's length, in characters. The first string is located at index 0.
topInsertAt
Inserts a string into the internal collection at a specified index. Using index 0 will insert at the beginning.
topLastString
Returns the last string in the internal collection.
Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
LoadFromFile
Loads strings from a file (one per line) into the internal collection. It is assumed the file contains ANSI strings. To load from a file containing non-ANSI strings (such as utf-8), call LoadFromFile2 instead.
Note: This method appends the strings in path to the existing collection of strings contained in this object.
Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
LoadFromFile2
Loads strings from a file (one per line) into the internal collection. The charset specifies the character encoding (such as utf-8) of the strings contained in the file.
Note: This method appends the strings in path to the existing collection of strings contained in this object.
Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
LoadFromText
Loads strings from an in-memory string (one per line) into the internal collection.
Note: This method appends the strings in str to the existing collection of strings contained in this object.
Pop
Returns the last string and removes it from the internal collection.
Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
Prepend
Adds a string to the beginning of the internal collection.
topRemove
Removes all strings equal to the string argument from the internal collection.
topRemoveAt
Removes the string at a particular index.
Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
ReplaceAt
Replaces the string at a specified index.
topSaveNthToFile
Saves the Nth string in the collection to a file.
Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
SaveToFile
Saves the collection of strings to a file, one string per line. Strings are saved using the ANSI charset. (Call SaveToFile2 to specify a charset, such as utf-8)
Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
SaveToFile2
Saves the collection of strings to a file, one string per line. Strings are saved using the specified charset.
Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
SaveToText
Writes the collection of strings to a single string, one per line (separated by CRLF line endings).
Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
Serialize
Returns an string which is an encoded representation of all the strings in the collection. The string collection can be re-created by calling the AppendSerialized method.
Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
Sort
Sorts the strings in the collection in ascending or descending order. To sort in ascending order, set ascending to true, otherwise set ascending equal to false.
SplitAndAppend
Splits a string at a character or substring boundary and adds each resulting string to the internal collection.
topStrAt
Returns the string at a specific index.
Throws ChilkatException on failure; e.getLastErrorText() (or the object's getLastErrorText()) explains why, and the object remains usable.
Subtract
Subtracts the strings contained within stringArrayObj from the caller's internal collection.
Union
Performs the union set-operator. The result is that the caller will have a string collection that is the union of itself and stringArrayObj.