How to create a string array?

Thanks!

Use Create Array, Build Array, an array constant on the block diagram or front panel, for loop, etc. The best way depends on what the heck you're actually trying to accomplish. I suggest you provide some more details and maybe take a class or on-line tutorial. Info on leaning LabVIEW can be found here.

Similar Messages

  • How to create a String with a specific size?

    how to create a String with a specific size?
    For example I want to create different Strings with the size of 100 , 1000 or 63k byte?

    String are immutable so just initialize it with the number of characters you want.
    You might want to look at java.lang.StringBuffer and see if that's what you want.

  • How to avoid NullPointerException---String array created from JTextArea

    Hi,
    I use the method getText() to put the contents of a JTextArea into a String object. Then I use split("\\s+") on that String object to get a String array. Before the contents of the String array are output, I get a NullPointerException. How do I avoid this exception? My code is below.
    //: net/mindview/util/SwingConsole.java
    package net.mindview.util;
    import javax.swing.*;
    public class SwingConsole {
      public static void
      run(final JFrame f, final int width, final int height) {
        SwingUtilities.invokeLater(new Runnable() {
          public void run() {
            f.setTitle(f.getClass().getSimpleName());
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.setSize(width, height);
            f.setVisible(true);
    } ///:~
    //: gui/Charts.java
    package gui;
    import javax.swing.*;
    import javax.swing.event.*;
    import java.awt.*;
    import java.awt.event.*;
    import net.mindview.util.SwingConsole;
    public class Charts extends JFrame {
        private int[] numbers;
        private JTextArea input = new JTextArea();
        private JScrollPane areaScrollPane = new JScrollPane(input);
        private JButton b1 = new JButton("Submit");
        private JButton b2 = new JButton("Clear");
        public Charts() {
            add(areaScrollPane);
            areaScrollPane.setPreferredSize(new Dimension(250, 250));
            b1.addActionListener(a1);
            b2.addActionListener(a2);
            add(b1);
            add(b2);
        private ActionListener a1 = new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                String data = input.getText();
                String[] stringArray = data.split("\\s+");
                for (String s:stringArray)
                    System.out.print(s + " ");
                int i = 0;
                for (String s:stringArray)
                    numbers=Integer.parseInt(s);
    i++;
    private ActionListener a2 = new ActionListener() {
    public void actionPerformed(ActionEvent e) {
    input.setText("");
    * @param args the command line arguments
    public static void main(String[] args) {
    // TODO code application logic here
    SwingConsole.run(new Charts(), 400, 400);
    Edited by: gluedtothecomputer on Feb 1, 2009 7:59 PM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

    don't forget to init your int array:
          String[] stringArray = data.split("\\s+");
          numbers = new int[stringArray.length];

  • How to create a String with comma ?

    Hi All,
    I have a table with 10 records(employee name) and i have to make a string
    with comma delimiter and at the end with "."
    Can anybody tell me how to write a Java program for this ?
    Thanks in advance.

    // I believe the following example gives you the answer.
    class stringEG {
         public static void main(String args[]) {
         String emprs[] ={"1","2","3","4","5","6","7","8","9","10"};
         String vempname = "";
         for(int i=0; i<emprs.length; i++) {
         if(i == (emprs.length-1))
              vempname = vempname + emprs[i] + ".";
         else
              vempname = vempname + emprs[i] + ", ";
         System.out.println("vempname : "+vempname);
    Here dont assume that I asked you to get all the results and putting
    it into the string arrays. But its a simple example to suit your requirement.
    The half-way coding below answers your question, I hope.
    vempname = "";
    while (emprs.next()) {
    if(emprs.isLast())
    vempname = vempname + emprs.getString("empname") + ".";
    else
    vempname = vempname + emprs.getString("empname") + ", ";
    // nats.

  • How to create an new array from dynamically discovered type

        public static Object toAdjustedArray(Object source, Object addition,
                                             int colindex, int adjust) {
            int newsize = 0;
            Class componentType = null;
            if (source.getClass().isArray()) {
                Object[] arrayIn= (Object[])source;
                componentType = arrayIn[0].getClass();
                newsize = arrayIn.length + adjust;
            else {
                System.out.println("error in ArrayUtil");
            Object[] newarray = new Object[newsize];
            copyAdjustArray(source, newarray, addition, colindex, adjust);
            return newarray;
        }This methods take an array as an input an append new value(s) to it.
    I can get the component type of the array (i.e. the class of the array's member). But how can I create a new array of this component type (i.e doing something like componentType[] newarray = new componentType[newsize])?
    CU Jerome

    I fanally found a walkaround trick for my problem.
    Their is no way to create an array of a certain type (dynamically dsicovered) in CLDC. But what you can do is to use the instanceof method to determine the type of your array and in a big if statement create the right array.
    Here is the final code:
        public static Object toAdjustedArray(Object source, Object addition,
                                             int colindex, int adjust) {
            int newsize = 0;
            if (source.getClass().isArray()){
                Object[] arrayIn= (Object[])source;
                newsize = arrayIn.length + adjust;
            Object arrayElement = null;
            if (addition.getClass().isArray()){
                Object[] temp = (Object[])addition;
                arrayElement = temp[0];
            else{
                arrayElement = addition;
            Object newarray = null;
            if (arrayElement == null){
                newarray = new Object[newsize];
            if (arrayElement instanceof org.hsqldb.Index){
                newarray = new org.hsqldb.Index[newsize];
            else {
                newarray = new Object[newsize];
            copyAdjustArray(source, newarray, addition, colindex, adjust);
            return newarray;
        }

  • Low-end RAID - Ugh (Or how to create partition level arrays)

    Ok... I got a new mobo and my system is up and running!
    Now let me tell you how I "want" to configure my drives.
    I have two Hitachi 160 SATA drives.  I would like to create two RAID partitions.  Configured like so:
    SATA1        SATA2
    20GB     +    20GB     @ Mirrored    =  20GB C:  (For Windows, etc.)  (Safe)
    140GB   +    140GB   @ Stripped    =  280GB  D:  (For everything else )  (Fast)
    The problem is that the stupid Nvidia RAID BIOS only seems to support creating drive level arrays and not partition level! 
    I only have expierence with high-end server RAID controllers and doing what I have layed out is perfectly possible.  Is this just something that "low-end" RAID controllers do not support?
    Thanks!

    Unfortunatly that is true, this controller does not support partition level arrays, only disc level.
    Be well....

  • How to create a string indicator with a history?

    I'm interested in creating a string indicator that has a history to it, possibly with time stamps attached to it.
    For those who have used AutoCAD it would be exactly like the command bar. A plus would be if I could only
    save the last 100 entries to keep the size memory usage down.
    Any thoughts? Does anyone have a code segment of this? 

    Keep a line count and once you go over your limit search the string for the first new line and split it at that point.
    Mark Yedinak
    "Does anyone know where the love of God goes when the waves turn the minutes to hours?"
    Wreck of the Edmund Fitzgerald - Gordon Lightfoot

  • How to create a string with numbers, separated by ",".

    Hello!
    I have a start number and a end number. For example 101 and 110.
    Now I want to create a string containing all numbers between 101 and 110 separated by comma(",").
    (101,102,103 .......,110)
    Any smart suggestions?

    Hello EKrille,
    I changed the vi from tst to give the same results on both options...
    Best regards,
    GerdW
    Best regards,
    GerdW
    CLAD, using 2009SP1 + LV2011SP1 + LV2014SP1 on WinXP+Win7+cRIO
    Kudos are welcome
    Attachments:
    string.vi ‏26 KB

  • How to create a list/array off numbers with boolean attributes

    Hi,
         Maybe the title doesn't explain this too well but what I'm trying to do I'd imagine should be straight forward, I just don't know how!
    I want an array of numbers to be entered by a user, and for each of these numbers I wish to have a boolean, (it will select later what action is performed on that number)
    The array size can vary
    e.g.
    element       Numeric Value              Boolean
    0                       5                             True
    1                       20                           True
    2                       -5                            False
    3                       10                           True
    n                       100                         False
    I don't see any list with numeric and boolean, maybe I just haven't spotted it or do I have to make it somehow?
    Any suggestions please?
    Thanks!
     p.s. if anyone else is using Opera Browser to post here, hitting enter work properly for ye when entering text? For me it causes the cursor to go up one line instead of down! Drives me nuts! It only happens with this NI forum
    Solved!
    Go to Solution.

    Hi thanks for the reply, 
                              It not really what I'm looking for though. 
    I require is a control that inputs both numeric and boolean,  as in the example I mentioned. I guess I'm looking for a cluster really but I thought there may be something more straight forward.
    From the example I gave  
    Element 0 of this array has been entered as a x, and the boolean True was entered (so I perform a "test" A on value x)
    Element 1 of this array has been entered as a y, and the boolean True was entered (so I perform a "test" A on value y)
    Element 2 of this array has been entered as a z, and the boolean False was entered (so I perform a "test" B on value z)
    I could also use a 2d array were I enter another numeric value (0/1 for False/True) but I'm not sure I can limit this column only to accept 0 or zero and the first row any number.
    I was hoping there would be some easier way to do this

  • How to import a string array from labview into DIAdem Spreadsheet/table

    How to set up a diadem template so when using labview diadem express, the values are imported into a table.
    I have values such as gain, corner frequency, and pass/fail that exist in arrays generated from collecting information from a 7 electrode EEG system.  I want to create a table/spreadsheet in DIAdem that imports the data when using the LabVIEW DIAdem express function, into a table or spread sheet?
    Any takers?
    -Regards
    eximo
    UofL Bioengineering M.S.
    Neuronetrix
    "I had rather be right than be president" -Henry Clay
    Solved!
    Go to Solution.

    Hi eximo,
    The DIAdem Report express block makes it easy to populate text boxes and 2D graphs in DIAdem from variables (wires) in LabVIEW.  Unfortunately neither 2D tables nor 3D graphs are implemented in the DIAdem Rerpot express block.  So you've got 2 options.
    Option 1:  if you don't have too many strings that you want to display, you can arrange that many text boxes into the shape of a 2D table and use the DIAdem Report express block as it was intended (sending data to it from LabVIEW wires).
    Option 2:  at some point as you continue to add elements to your report, you'll probably end up here.  The DIAdem Report express block was designed to connect LabVIEW wires with simple DIAdem reports.  But there is a hook you can use in the DIAdem Report express block to run a VBScript instead of loading a REPORT template *.TDR file.  With a DIAdem VBScript you can accomplish anything in DIAdem.  In addition to wiring up a VBScript path instead of a REPORT template path, you'll also need to send all the data you want to report on to a TDMS file and have DIAdem read the data from that file, instead of receiving the data directly from the LabVIEW wire at the express block's input terminal.  This is a little more complicated, but it will allow you to do absolutely anything you want to in DIAdem and start that report from LabVIEW.
    I'm attaching an example of Option 2, but I'd be willing to help you adapt it to your data and reporting needs if you'll post or email ([email protected]) your data set and a rough *.TDR file of what you want in REPORT.  It's pretty slow here at the office over Christmas, so I've got time....
    Brad Turpin
    DIAdem Product Support Engineer
    National Instruments
    Attachments:
    DIAdem Report File.zip ‏90 KB

  • How to create an collection/array/object/thingy from a bunch of objects for eventual export to CSV.

    This is a follow-up to an earlier post (How
    to output a bunch of variables into a table.) Now that I can ouput data for a single computer I need to to do the same for a list of computers into a CSV. In more general terms how do I get a bunch of $Computer objects into a single collection/array/object/thingy
    with a clever name like $Computers?
    # http://ss64.com/ps/get-wmiobject-win32.html
    # http://social.technet.microsoft.com/Forums/en-US/da54b6ab-6941-4e45-8697-1d3236ba2154/powershell-number-of-cpu-sockets-wmi-query?forum=winserverpowershell
    # http://serverfault.com/questions/10328/determine-cpu-processors-vs-sockets-though-wmi
    # http://social.technet.microsoft.com/Forums/windowsserver/en-US/8443fcfd-5a0b-4c3d-bda7-26df83d2ee92/how-to-output-a-bunch-of-variables-into-a-table?forum=winserverpowershell
    Param(
    [Parameter(Mandatory=$false,ValueFromPipeline=$true)]
    [string]$ComputerName = $env:COMPUTERNAME,
    [Parameter(Mandatory=$false,ValueFromPipeline=$false)]
    [ValidateScript(
    If ( $_ -ne $null ) { Test-Path $_ }
    [String]$ComputerListFile
    Function Get-Computer
    Param(
    [string]$ComputerName
    $Win32_PingStatus = $null
    $Win32_PingStatus_Result = $null
    $Win32_OperatingSystem = $null
    $Win32_Processor = $null
    $Win32_PhysicalMemory = $null
    $Win32_ComputerSystem = $null
    $Win32_BIOS = $null
    $Computer = $null
    $Win32_PingStatus = "select * from Win32_PingStatus where address = '$ComputerName'"
    $Win32_PingStatus_Result = Get-WmiObject -query $Win32_PingStatus
    If ( $Win32_PingStatus_Result.protocoladdress )
    "$ComputerName ping succeeded."
    $Win32_OperatingSystem = Get-WmiObject Win32_OperatingSystem -computer $ComputerName -ErrorAction SilentlyContinue
    If ( $Win32_OperatingSystem -eq $null)
    "$ComputerName WMI failed."
    } Else {
    "$ComputerName WMI succeeded."
    $Win32_Processor = [object[]]$(Get-WmiObject Win32_Processor -computer $ComputerName)
    $Win32_PhysicalMemory = [object[]]$(Get-WmiObject Win32_PhysicalMemory -computer $ComputerName)
    $Win32_ComputerSystem = Get-WmiObject Win32_ComputerSystem -computer $ComputerName
    $Win32_BIOS = Get-WmiObject Win32_BIOS -computer $ComputerName
    $Computer = New-Object -Type PSObject -Property @{
    Name = $Win32_OperatingSystem.CSName
    Win32_BIOS_SerialNumber = [string]$Win32_BIOS.SerialNumber
    Win32_ComputerSystem_Manufacturer = [string]$Win32_ComputerSystem.Manufacturer
    Win32_ComputerSystem_Model = [string]$Win32_ComputerSystem.Model
    #Win32_ComputerSystem_NumberOfLogicalProcessors = [int32]$Win32_ComputerSystem.NumberOfLogicalProcessors
    #Win32_ComputerSystem_NumberOfProcessors = [int32]$Win32_ComputerSystem.NumberOfProcessors
    Win32_ComputerSystem_TotalPhysicalMemory = [long]$Win32_ComputerSystem.TotalPhysicalMemory
    Win32_ComputerSystem_TotalPhysicalMemory_GB = [float]($Win32_ComputerSystem.TotalPhysicalMemory / (1024*1024*1024))
    Win32_OperatingSystem_Caption = [string]$Win32_OperatingSystem.Caption
    Win32_OperatingSystem_CSName = [string]$Win32_OperatingSystem.CSName
    #Win32_OperatingSystem_OSArchitecture = [string]$Win32_OperatingSystem.OSArchitecture
    #Win32_OperatingSystem_SerialNumber = [string]$Win32_OperatingSystem.SerialNumber
    Win32_OperatingSystem_ServicePackVersion = [string]$Win32_OperatingSystem.ServicePackMajorVersion + "." + [string]$Win32_OperatingSystem.ServicePackMinorVersion
    Win32_PhysicalMemory_Capacity = ($Win32_PhysicalMemory | ForEach-Object { $_.Capacity } | Measure-Object -Sum).sum
    Win32_PhysicalMemory_Capacity_GB = (($Win32_PhysicalMemory | ForEach-Object { $_.Capacity } | Measure-Object -Sum).sum / (1024*1024*1024))
    Win32_Processor_Count = [int]$Win32_Processor.Count
    Win32_Processor_NumberOfCores = [string]$Win32_Processor[0].NumberOfCores
    Win32_Processor_NumberOfLogicalProcessors = [string]$Win32_Processor[0].NumberOfLogicalProcessors
    #Win32_Processor_Description = [string]$Win32_Processor[0].Description
    Win32_Processor_Manufacturer = [string]$Win32_Processor[0].Manufacturer
    Win32_Processor_Name = [string]$Win32_Processor[0].Name
    } ## end new-object
    $Computer
    } Else {
    "$ComputerName ping failed."
    $ComputerNameMgmt = $ComputerName + "-mgmt"
    $Win32_PingStatus = "select * from Win32_PingStatus where address = '$ComputerNameMgmt'"
    $Win32_PingStatus_Result = Get-WmiObject -query $Win32_PingStatus
    If ( $Win32_PingStatus_Result.protocoladdress )
    "$ComputerNameMgmt ping succeded."
    } Else {
    "$ComputerNameMgmt ping failed."
    "$(Get-Date -Format o) Starting script $($MyInvocation.MyCommand.Name)"
    If ( $ComputerListFile -eq $null -or $ComputerListFile.Length -eq 0 )
    "Processing computer $ComputerName"
    Get-Computer( $ComputerName )
    } Else {
    "Processing computer list $ComputerList"
    $ComputerList = Get-Content $ComputerListFile
    $Computers = @{}
    $Results = @()
    ForEach( $ComputerListMember in $ComputerList )
    "$(Get-Date -Format o) $ComputerListMember"
    # Get-Computer( $ComputerListMember ) | Add-Member -InputObject $Computers -MemberType NoteProperty -Name $_
    # http://social.technet.microsoft.com/Forums/windowsserver/en-US/e7d602a9-a808-4bbc-b6d6-dc78079aafc9/powershell-to-ping-computers
    # $Compuers += New-Object PSObject -Property $Props
    # $Computers += New-Object PSObject -Property Get-Computer( $ComputerListMember )
    Get-Computer( $ComputerListMember )
    "$(Get-Date -Format o) Ending script $($MyInvocation.MyCommand.Name)"
    If I try something like this:
    Get-Computer( $ComputerListMember ) | Add-Member -InputObject $Computers -MemberType NoteProperty -Name $_
    I get the following, even though $_.Name is not null.
    Add-Member : Cannot bind argument to parameter 'Name' because it is null.
    At <path to my script>Get-Hardware_Memory_OSVersion_CPU_Cores_ver04_sanitized.ps1:111 char:107
    + Get-Computer( $ComputerListMember ) | Add-Member -InputObject $Computers -MemberType NoteProperty -Name <<<< $_
    + CategoryInfo : InvalidData: (:) [Add-Member], ParameterBindingValidationException
    + FullyQualifiedErrorId : ParameterArgumentValidationErrorNullNotAllowed,Microsoft.PowerShell.Commands.AddMemberCommand
    Or if I try this:
    $Computers += New-Object PSObject -Property Get-Computer( $ComputerListMember )
    I get this:
    New-Object : Cannot bind parameter 'Property'. Cannot convert the "Get-Computer" value of type "System.String" to type "System.Collections.Hashtable".
    At <path to my script>Get-Hardware_Memory_OSVersion_CPU_Cores_ver04_sanitized.ps1:114 char:47
    + $Computers += New-Object PSObject -Property <<<< Get-Computer( $ComputerListMember )
    + CategoryInfo : InvalidArgument: (:) [New-Object], ParameterBindingException
    + FullyQualifiedErrorId : CannotConvertArgumentNoMessage,Microsoft.PowerShell.Commands.NewObjectCommand

    Hi Aenagy,
    If you want to combine all the computers' information to a single array, and add the property computername in the output, please also try the script below, which I make a little modification of the function Get-Computer, pleaese make sure the account running
    the script has the admin permission of the remote computers, or you need to privide cridentials in get-wmiobject, also note I haven't tested:
    $output = @()#to output information of the all the computers
    ForEach( $ComputerName in $ComputerList ){#loop all the computers
    $Win32_PingStatus = "select * from Win32_PingStatus where address = '$ComputerName'"
    $Win32_PingStatus_Result = Get-WmiObject -query $Win32_PingStatus
    If ( $Win32_PingStatus_Result.protocoladdress )
    "$ComputerName ping succeeded."
    $Win32_OperatingSystem = Get-WmiObject Win32_OperatingSystem -computer $ComputerName -ErrorAction SilentlyContinue
    If ( $Win32_OperatingSystem -eq $null)
    "$ComputerName WMI failed."
    Else {
    "$ComputerName WMI succeeded."
    $Win32_Processor = [object[]]$(Get-WmiObject Win32_Processor -computer $ComputerName)
    $Win32_PhysicalMemory = [object[]]$(Get-WmiObject Win32_PhysicalMemory -computer $ComputerName)
    $Win32_ComputerSystem = Get-WmiObject Win32_ComputerSystem -computer $ComputerName
    $Win32_BIOS = Get-WmiObject Win32_BIOS -computer $ComputerName
    $Computer = New-Object -Type PSObject -Property @{
    Computername = $ComputerName #add the property computername
    Name = $Win32_OperatingSystem.CSName
    Win32_BIOS_SerialNumber = [string]$Win32_BIOS.SerialNumber
    Win32_ComputerSystem_Manufacturer = [string]$Win32_ComputerSystem.Manufacturer
    Win32_ComputerSystem_Model = [string]$Win32_ComputerSystem.Model
    #Win32_ComputerSystem_NumberOfLogicalProcessors = [int32]$Win32_ComputerSystem.NumberOfLogicalProcessors
    #Win32_ComputerSystem_NumberOfProcessors = [int32]$Win32_ComputerSystem.NumberOfProcessors
    Win32_ComputerSystem_TotalPhysicalMemory = [long]$Win32_ComputerSystem.TotalPhysicalMemory
    Win32_ComputerSystem_TotalPhysicalMemory_GB = [float]($Win32_ComputerSystem.TotalPhysicalMemory / (1024*1024*1024))
    Win32_OperatingSystem_Caption = [string]$Win32_OperatingSystem.Caption
    Win32_OperatingSystem_CSName = [string]$Win32_OperatingSystem.CSName
    #Win32_OperatingSystem_OSArchitecture = [string]$Win32_OperatingSystem.OSArchitecture
    #Win32_OperatingSystem_SerialNumber = [string]$Win32_OperatingSystem.SerialNumber
    Win32_OperatingSystem_ServicePackVersion = [string]$Win32_OperatingSystem.ServicePackMajorVersion + "." + [string]$Win32_OperatingSystem.ServicePackMinorVersion
    Win32_PhysicalMemory_Capacity = ($Win32_PhysicalMemory | ForEach-Object { $_.Capacity } | Measure-Object -Sum).sum
    Win32_PhysicalMemory_Capacity_GB = (($Win32_PhysicalMemory | ForEach-Object { $_.Capacity } | Measure-Object -Sum).sum / (1024*1024*1024))
    Win32_Processor_Count = [int]$Win32_Processor.Count
    Win32_Processor_NumberOfCores = [string]$Win32_Processor[0].NumberOfCores
    Win32_Processor_NumberOfLogicalProcessors = [string]$Win32_Processor[0].NumberOfLogicalProcessors
    #Win32_Processor_Description = [string]$Win32_Processor[0].Description
    Win32_Processor_Manufacturer = [string]$Win32_Processor[0].Manufacturer
    Win32_Processor_Name = [string]$Win32_Processor[0].Name
    } ## end new-object
    $output+=$Computer #combine all the "$computer" to "$output"
    Else {
    "$ComputerName ping failed."
    $output
    If you have any feedback on our support, please click here.
    Best Regards,
    Anna
    TechNet Community Support

  • How to create an Object array(two dimensional) from a properties file..

    Hi All..
    I have a typical problem..
    I have a properties file with key/value pairs . Now what I want to do is.. I need to read all the keys and the values corresponding to that keys and then create a two dimensional array.. Like..
    Properties props;
    Object[][] contents;
    My contents should be like
    contents = {{key1,value1},{key2,value2},{key3,value3},...};
    Can someone tell me how to do this.. asap...
    TIA
    CK

    Just because something is difficult for you does not qualify it as an "Advance Language Topic"... And it certainly doesn't allow you to multi-post.

  • Quickie - How to create a ArrayList Array?

    Hi,
    I hope this has a quick answer. What I'm trying to do is create an Array of ArrayList objects to replace a ragged array I had for strings. Basically the length of each 'row' of the array can be variable and I want to take advantage of ArrayLists features. So I created ArrayList
    as below:
    ArrayList[] headerInfo = new ArrayList[3];
    headerInfo[0] = new ArrayList<String>();  
    headerInfo[0].add("aString");If I iterate through each arrayList using a for each loop, will the order be preserved? Or is there a better way to achieve a 'variable length' ragged array?
    Thanks.

    Also, if you end up having to keep a large number of empty spaces in your lists/arrays (so that the "x" and "y" line up with the object you are trying to represent), you can try a Map to reduce the overall memory needed (because you won't need to keep a space for "x,y" pairs that don't have a corresponding value). Your key can be a String generated as:
    String key = x + "," + y;Then your map could be:
    Map<String, String> myStrings = new HashMap<String, String>();The getString method would be:
    return myStrings.get(x+","+y);or the key could be a simple class:
    [For a HashMap, you need hashCode--maybe add the hashCode provided by Integer class for x to the hashCode provided by Integer class for y--I don't know a lot about implementing hashCodes, but that sounds possibly reasonable.]
    class Pair {
       private final int x;
       private final int y;
       Pair(int x, int y) {
          // set values
       // define "equals" (x == other.x, y == other.y)
       // define "hashCode"
       // define "toString" for debugging purposes
    Map<Pair, String> myStrings = new HashMap<Pair, String>();The getString method would be:
    return myStrings.get(new Pair(x, y));For mathematics, if the 2-d array was a numerical matrix, this HashMap would implement what is called a "sparse matrix".
    The map doesn't change your other classes. The other classes would still call:
    String myString = someClass.getString(2, 4);

  • How to create XML string for an object matching the result of a marshal?

    I'm trying to create a XML string representation of an object which exactly matches the XML which results from marshalling the object into a request. I'm almost there except that the XML string I come up with is missing the attribute "standalone=\"yes\"" in the topmost xml element, and this attribute is present in the marshalled XML. I'm using the XML string to create a payload signature which must match exactly with the XML payload of the request, so the two XML representations of the object really do need to be identical.
    Here's what I'm doing to create the XML from the object:
       private String myObjectToXmlString (final MyObject myObject)
           throws Exception {
                 try {
               DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
               Document document = documentBuilder.newDocument();
               myObjectMarshaller.marshal(myObject, document);
               Source source = new DOMSource(document);
               StringWriter stringWriter = new StringWriter();
               Result result = new StreamResult(stringWriter);
               TransformerFactory factory = TransformerFactory.newInstance();
               Transformer transformer = factory.newTransformer();
               transformer.transform(source, result);
               return stringWriter.getBuffer().toString();
           } catch (Exception ex) {
               throw new Exception("Unable to convert a MyObject object to an XML String -- " + ex.toString(), ex);
       }The XML which is produced looks like this:
    <?xml version=\"1.0\" encoding=\"UTF-8\"?>
    <ns2:myObject xmlns:ns2=\"http://sunconnection.sun.com/xml\">
       <myObjectId>0</myObjectId>
       <objectType>1</objectType>
       <description>Test Object</description>
    </ns2:myObject>The payload object is marshalled to the request like so:
        // marshall the MyObject to the output stream
       OutputStream outputStream = myHttpUrlConnection.getOutputStream();
       myObjectMarshaller.marshal(myObject, outputStream);
       outputStream.flush();
       outputStream.close();When I view the XML payload of the request it looks like this:
    <?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>
    <ns2:myObject xmlns:ns2=\"http://sunconnection.sun.com/xml\">
       <myObjectId>0</myObjectId>
       <objectType>1</objectType>
       <description>Test Object</description>
    </ns2:myObject>As you can see the two XML representations of the object are identical except for the standalone attribute in the xml element.
    It'd be a hack to make the assumption that the standalone attribute will always be there in the marshalled object and to just hard code it into the XML string returned by my object to XML method. Since I'm using the same Marshaller to create the XML string as I am to perform the marshalling to the request I assume that there's some way to make it give the same XML in both cases, and that I'm doing something wrong in my method which converts the object to an XML string. If anyone can see where I'm going wrong in that method (myObjectToXmlString() above), or can suggest a better way of doing this, then I'll certainly appreciate the insight.
    --James                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

    It turns out that I was taking the wrong approach in my object to XML string method. A cleaner/better way to do it, which gives the correct result, is this:
        private String myObjectToXmlString (final MyObject myObject)
            throws Exception {
            try {
                ByteArrayOutputStream stream = new ByteArrayOutputStream();
                myObjectMarshaller.marshal(myObject, stream);
                return stream.toString();
            } catch (Exception ex) {
                throw new Exception("Unable to convert a MyObject object to an XML String -- " + ex.toString(), ex);
        }--James                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       

  • How to create XML string from BPM Business Object?

    Hello,
    I have a business object in my BPM project and I need to transform it in a XML string:
    From:
    Business Object: Customer
    Properties:          Name, Age
    To:
    "<Customer><Name>Robert</Name><Age>17</Age></Customer>"
    How can I do this?
    Thanks.

    Hello,
    I have a business object in my BPM project and I need to transform it in a XML string:
    From:
    Business Object: Customer
    Properties:          Name, Age
    To:
    "<Customer><Name>Robert</Name><Age>17</Age></Customer>"
    How can I do this?
    Thanks.

Maybe you are looking for

  • How to filter the Event Data from the EventHub when consuming data?

    We know the EventHub has the filter function. I'm designing a new solution for a customer and it looks like EventHubs are great for sending and receiving our near-realtime data. Downside is when receiving the data, we receive all data of all our devi

  • My ipod wont appear in my itunes, why? what do i need to do to fix it?

    I m trying to add music to my ipod but when i connect my ipod to itunes it dont show up? is it my computer or is it my ipod touch???

  • Are the calendar problems fixed

    i remember many people having trouble when working with calendars (losing photo libs, i think). has that problem been fixed in 6.0.1?

  • 26-suspend2 error: "Some modules failed to unload: nvidia"

    I've been trying to install the suspend2 kernel to allow my machine to hibernate, but I can't get it to work from within X (though it seems to work fine in run level 3).  When I try, I get: $ sudo hibernate Password: :: Saving ALSA Levels [DONE] Some

  • Essvbase Drill down

    Is it possible to drill down to Relational databases from Essbase hierarchy instead of navigation? I have an Essbase dimension called "Time" that is spread accross four generations. The last generation Gen4 is month. I have the day details in the Fac