How do I make an Array Of Strings

I want to make a program that will accept up to 10 lines of text but maybe less depending on the what the user want to put in... i can't seem to figure out where i put the number after a string... after String [10] text; or String text[10]?? am i even going about this correctly??
thanks,
Disco Hristo

No, you are not.
You need to do something like:
String [] text = new String[ 10 ];Remember, Java creates all objects on the Heap. So you tell an array the appropriate size to be when you actually allocate an array with new.

Similar Messages

  • How do you make an array of image icons and then call them?

    How do you make an array of image icons and then call them, i have searched all over the internet for making an array of icons, but i have
    found nothing. Below is my attempt at making an array of icons, but i cant seem to make it work. Basically, i want the image to match the value of the roll of the dice (rollVal)
    Any help would be greatly appreciated, some code or link to tuturial, ect.
    /** DiceRoller.java
    * Roll, print, Gui
    import javax.swing.*;
    public class DiceRoller extends JFrame
         private ImageIcon[] image  ;
         public String[] images = { "empty", "dice1.jpg",
                   "dice2.jpg", "dice3.jpg", "dice4.jpg",
                   "dice5.jpg", "dice6.jpg" };
         public Dice die;
         private int rollVal;
         public int rollNum;
         private JLabel j1;
         public DiceRoller(){
              j1= new JLabel("");
           die =new Dice();
           int rollVal;
           rollVal = die.roll();     
           image = new  ImageIcon[images.length];
         for(int i = 0; i < images.length; i++){
          image[i] = new ImageIcon(images);
         if (image!=null){
              j1.setIcon(image[rollVal]);
         System.out.println("Roll = "+die.roll());

    Demo:
    import java.awt.*;
    import java.net.*;
    import javax.swing.*;
    public class IconExample {
        public static void main(String[] args) {
            EventQueue.invokeLater(new Runnable(){
                public void run() {
                    launch();
        static void launch() {
            try {
                Icon[] icons = new Icon[6];
                for(int i=0; i<icons.length; ++i) {
                    String url = "http://www.eureka-puzzle.be/cast/images/dice" + (i + 1) + ".jpg";
                    icons[i] = new ImageIcon(new URL(url));
                display(icons);
            } catch (MalformedURLException e) {
                throw new RuntimeException(e);
        static void display(Icon[] icons) {
            JPanel cp = new JPanel();
            for(Icon icon : icons) {
                cp.add(new JLabel(icon));
            JFrame f = new JFrame();
            f.setContentPane(cp);
            f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
            f.pack();
            f.setLocationRelativeTo(null);
            f.setVisible(true);
    }

  • How do I make an Array of an object?

    If I have the following class:
    public class myStruct {
         String pid;
         String name;
    How do I make an array of myStruct's?
    I tried to do something like this
    public class MyTest {
    public static void main ( String [] args ) {
         System.out.println( "test myStruct");
         myStruct [] k = new myStruct[ 10 ];
         k[0].pid = "1";
         k[0].mnemonic = "test";
         System.out.println( k[0].pid );
    It compiles, but I get "Exception in thread "main" java.lang.NullPointerException at MyTest.main
    I know I am doing something wrong, any ideas how I could do something like this?

    in class myStruct,
    public class myStruct {
    String pid;
    String name;
    there is no 'String mnemonic;".
    in class MyTest, you have a line that reads
    k[0].mnemonic = "test";
    when there is no String mnemonic in myStruct. maybe that's why.

  • How do I pass an array of strings? (Help Me... Please!!! .Read Me....)

    Dear All.
    Help Me...
    English is not very good. Google translator is used.
     How do I pass an array of strings?
    Please refer to the VB program
     ===========================================
    Private Sub m_btn_Click()
        Dim nReturn As Long
        Dim sPpid As String
        Dim sMdln As String
        Dim sSoftRev As String
        Dim nCount As Long
        Dim saCCodes(2) As String
        Dim naPCount(2) As Long
        Dim saPNames(10) As String
        sPpid = "PPID001"
        sMdln = "Mdln"
        sSoftRev = "Rev001"
        nCount = 2
        saCCodes(0) = "1"
        naPCount(0) = 5
        saPNames(0) = "Param001"
        saPNames(1) = "Param002"
        saPNames(2) = "Param003"
        saPNames(3) = "Param004"
        saPNames(4) = "Param005"
        saCCodes(1) = "2"
        naPCount(1) = 5
        saPNames(5) = "Param006"
        saPNames(6) = "Param007"
        saPNames(7) = "Param008"
        saPNames(8) = "Param009"
        saPNames(9) = "Param010"
        nReturn = m_XGem.GEMReqSend(sPpid, sMdln, sSoftRev, nCount, saCCodes(0), naPCount(0), saPNames(0))
        If (nReturn = 0) Then
            Call Me.AddMessage("[EQ ==> XGEM] GEMReqSend successfully")
        Else
            Call Me.AddMessage("[EQ ==> XGEM] Fail to GEMReqSend (" & nReturn & ")")
        End If
    End Sub
    =================================================
    nCount, naPCount enough saCCodes, saPNames value must be sent.
    How to handle an array of strings in LabView is impatient.
    I want to VB program implemented in LabView.

    Have you actually tried to right click on the according node parameter and select Create->Constant or Create-Control??
    And I don't see any string array in the parameter list. That are all simple strings and the VB code in your first post clearly shows that the call to the function only indexes the first element of those arrays to be passed to the function, not the entire array.
    If the function really reads arrays despite being declared as only taking strings then it is using some weirdo VB trickery and there will be no way to replicate that in LabVIEW.
    Rolf Kalbermatter
    CIT Engineering Netherlands
    a division of Test & Measurement Solutions

  • How to make an array of strings?

    Hi,
    In my VI i need to send 3 or more strings from a server to a client over a TCP/IP connection. the problem is that when i press the send button i need all the strings to be sent together so i assume i need an array but unfortunately i dont know how to build the array. i have attached my example to this post.
    i appreciate the help!
    Rambaldi.
    Solved!
    Go to Solution.
    Attachments:
    Array of String.vi ‏11 KB

    TCPIP expects thay you send the packet as a single string.  you should format this into a single string that the client can understand.  Use string formater or concatinate string.
    I would sue something like string1,string2,string3 or <string1><string2><string3>.
    Other oprions are to build a string array, fletten to string on client side unflatten and the use the array.
    Either way if you plan on sending 1 packet you will need a single formatted string and the client must understand the format.
    You gan even get fancy and use a format like xml so you can genericly process the strings at the client.
    Paul Falkenstein
    Coleman Technologies Inc.
    CLA, CPI, AIA-Vision
    Labview 4.0- 2013, RT, Vision, FPGA

  • How do I write an array of strings to a single Excel row?

    I'd like to write test data, as an array of strings, to an Excel file. Attached is my attempt to modify one of the Labview 6.1 example files. This modified example will write the data to the correct row, which is determined by serial # of the UUT, but to a new sheet for each unit. I'd like to do the same thing, but to just one sheet. This sheet's data would then be saved after 50 rows of collected test data.
    Thank you in advance,
    Tim Denson
    Attachments:
    Write Table To XL.vi ‏58 KB

    Sorry I didn't get back to faster on this. I've been out of town working and just really haven't had time.
    Yes,
    The Report Generation toolkit would make this very easy. If you have it, I'd suggest using it.
    The image shown below shows the five VIs from the toolkit that I've used to write to Excel.
    What this loop does is receive a string through a Queue, either open a
    template or open todays file, convert the tab delimited string to an
    array, write the array to the next line of the Excel file, Save (with
    todays date stamp if opened from the tempate) and close it. It's a good
    idea to always save and close teh file after each write if it's not
    being continuously written to. In this case, a new line will be written
    only once a minute or so. This lessens the chance of losing data if the
    machine locks up for some reason. Opening and closing does take time
    and can slow down a loop that needs to run at a certain rate. This loop
    actually runs in a background process and several other processes send
    data to it through the queue to be written. The queue can buffer
    several data streams if needed so you won't lose data if it's busy and
    you don't have to worry about two processes accessing the Excel sheet
    at the same time.
    Ed
    Message Edited by Ed Dickens on 02-18-2006 11:12 AM
    Ed Dickens - Certified LabVIEW Architect - DISTek Integration, Inc. - NI Certified Alliance Partner
    Using the Abort button to stop your VI is like using a tree to stop your car. It works, but there may be consequences.
    Attachments:
    RGTK Array to Excel.gif ‏14 KB

  • How do I resize an array of strings in a CIN ?

    I've been using a call to NumericArrayResize() to allocate enough memory for numeric arrays, but I now have an array of strings that I need to build in a DLL/CIN and pass back to Labview. Can someone point me to a snippet that will demonstrate how to populate an array of strings with data?
    Kindest,
    Warren

    Check the follwing example. It may be what you want:
    Using a CIN to Create an Array of Strings in LabVIEW
    http://zone.ni.com/devzone/devzoneweb.nsf/opendoc?openagent&AD517F5DCCAF70228625683A000A570F&cat=2F4F574886553A62862567AC004F032D
    Also, check the following example, as it provide an example on how to handle strings.
    Code Interface Node (CIN) That Converts a LabVIEW String to a C String, Modifies it, and Returns it as a LabVIEW String
    http://zone.ni.com/devzone/devzoneweb.nsf/opendoc?openagent&D978409908EA760D8625683A000B6B6E&cat=2F4F574886553A62862567AC004F032D
    Regards;
    EV
    www.vartortech.com

  • How can I resize an array of strings?

    I'm having a problem of not being able to use the CIN functions and therefore can't use the convenient resizing methods. I have tried to use NumericArrayResize to resize an array of strings, but it's not working correctly. Here's what I've tried most recently. I have tried many variations, so if you want to modify what I have posted, or just provide new code, please feel free.
    typedef struct {
    int32 dimSize;
    LStrHandle elt[1];
    } LStrHandleArray;
    typedef LStrHandleArray **LStrHandleArrayHandle;
    void someMethod(LStrHandleArrayHandle arrayOut) {
    // attempting to write the string "asdf" in the first element in the array. (1D array)
    int newSize = 1;
    MgErr e = NumericArrayResize(uL, 1L, (UHandle*)&arr
    ayOut, newSize);
    (*arrayOut)->dimSize = newSize;
    LStrHandle hdl = *(*arrayOut)->elt;
    long str_size = strlen("asdf");
    MgErr err = NumericArrayResize(uB, 1L,(UHandle *)&hdl, str_size);
    LStrLen(*hdl) = str_size;
    MoveBlock("asdf", LStrBuf(*hdl), str_size);
    The code above doesn't result in crashing labview at any time. The string "asdf" is not copied though. And, after being able to copy one string I would like to extend this to many elements in a 1D array of strings.
    Thanks!
    Naveen

    LabVIEW stores string arrays as an array of handles to those strings. To resize an array of strings you need to declare a new string in LabVIEW's data space, resize the handle array, and add a handle to your new string. Here is an example program which does this.
    -Aaron Marks
    National Instruments
    Attachments:
    resize.zip ‏252 KB

  • How can i combine an array of string and an array of integers ?

    i have an array of string data [to be used as header], and an array of multiple column integer vakues;i need them together in one file. 
    Am not able to combine them so that i can write them into a single file.
    Solved!
    Go to Solution.
    Attachments:
    string file input.txt ‏1 KB
    Test build_1.vi ‏13 KB

    There are a few ways you can do this.  What I recommend is:
    Open the file
    Use the Array to Spreadsheet String to turn your headers into a single string
    Write this to the file.
    Use the Array to Spreadsheet String to turn your numeric data into a single string
    Write this to the file.
    Close the file
    There are only two ways to tell somebody thanks: Kudos and Marked Solutions
    Unofficial Forum Rules and Guidelines

  • How to convert an int array to string array?

    Hi,
    Can anyone please help me with this question?
    int number={4,6,45,3,2,77};
    I like to convert this into a list and sort
    List mylist = Arrays.asList(number);
    Collections.sort(mylist);
    But first I need to convert the int array to String array.
    Please advise. Thanks.

    If you want to convert your int array to a String array, you have no choice but doing a conversion element by element in a for loop.
    However, if the sort method doesn't behave as desired, you can use the one with 2 parameters, the second parameter being a comparator class.
    Check the javadoc for more information : http://java.sun.com/j2se/1.3/docs/api/java/util/Collections.html
    /Stephane

  • Tokenizing a JTextArea(how do i make the JTextArea a string?)

    I am working on this text analyzer program which is kinda like a replica of what you find when you a do a word count in many office suites. It tells you stuff like number of sentences, longest sentence, shortest sentence and average length. Number of words, longest shortest and average word length. In addtion there is a word search to it.
    It took me a good 3 hours to realize that there was such a thing as a panel and I could impliment this to add more than one object to a borderlayout section.
    I think I have figured out everything with the StringTokenizer part, well except for how do add it to an array. Someone mentioned something to me about an
    islist.StringTokenizer or something, but I haven't been able to find anything else on this.
    Right now, however, my primary concern is how can I take input from a JTextArea and be able to parse it with the StringTokenizer, which to the best of my knowledge has to be a string. It this as simple as a getValue(); type thing or do i have to add some sort of action listener that finds out when it changes or something?
    thank you for your time

    I just figued out the JTextArea thing
    it is JTextArea.getText();
    im stupid :P

  • How do u make an array of objects

    I have 2 classes Helper and HelperWorker
    Helper has a constructor which looks like this public
    Helper(String Iname, double IhoursWorked) {
              name = Iname;
              hours = IhoursWorked;
    }I have two arrays in the HelperWorker class with the following values
    String Names[] = {"Tim Brown","Jack Blink","Pat Gold","Jim Done","Eloise Tricot"};
         double Work[] = {35,50,34,22,71};I need to create an array of Helper class objects, using the arrays Names and Work, representing 5 helpers with hours each of them worked.
    can some one help becuse i can not see any way I used a forloop to create an object but that only Initialize s the same object x number of times. also on arrays i wanted to know if i want to change the values of array x[2] with a varible y how do i append or replace the value at x[2].

    Try this:
    class Helper
         private String name="";
         private double hours;
         Helper(String Iname, double IhoursWorked)
              name = Iname;     
              hours = IhoursWorked;
         public void print()
              System.out.println("\nName : " +name);
              System.out.println("Hours : " +hours);
    public class HelperWorker
         String Names[] = {"Tim Brown","Jack Blink","Pat Gold","Jim Done","Eloise Tricot"};     
         double Work[] = {35,50,34,22,71};
         Helper[] helperArray=new Helper[Names.length];
         HelperWorker()
              Helper temp=null;
              for(int i=0;i<Work.length;i++)
                   temp=new Helper(Names,Work[i]);
                   helperArray[i]=temp;
              for(int i=0;i<Work.length;i++)
                   helperArray[i].print();     
         public static void main(String s[])
              new HelperWorker();

  • How do i make a array of user defined structure and creat a pointer for the same

    Function
    The prototype of the dll function is
    unsigned long PassThruIoctl(unsigned long A, unsigned long B, void *pvar1, void *pvar2);
    "void *pvar1" and "void *pvar2" are pointers to different Structures. The value of  "unsigned long B" will determine what kind of Structure the pointer will represent.
    One sample structure is given below when pvar1 is the pointer to SCONFIG_LIST.
    typedef struct
          unsigned long ParameterID;    // this an input to the dll
          unsigned long Value;          // this is an output from dll
    } SCONFIG;
    typedef struct
          unsigned long NumOfParams;    // the no. of elements(SCONFIG) in array
    (input)
          SCONFIG *ConfigPtr;           // the pointer to array of SCONFIG
    (input)
    } SCONFIG_LIST;
    The function is supposed to get the values of configuration parameters (from an external interfacing device).
    When I tried to run the function as shown in the attached VI, I always end up with error. The error I get is saying something about DLL corrupting the memory of Lab View.
    Solved!
    Go to Solution.

    What will be the structure for pVar2?
    One issue that I can see in you code is, for pvar1 instead of passing an array of clusters, you are passing a cluster of SCONFIG. Also you need to initialize the numbr of elements in the array before passing it to the DLL (see attached code). In this I have assumed that pVar2 is also expecting a similar input.
    I was not able to run the code here becasue the dll is not there. So please try and let me know.
    "A VI inside a Class is worth hundreds in the bush"
    യവന്‍ പുലിയാണു കേട്ടാ!!!
    Attachments:
    GETCONFIG_2.vi ‏9 KB

  • How to get correct byte array from String

    I have a string which contains binary value from 0 to 255. Now, if I use String.getBytes(),all the chars in the string which range from 128 to 160 will be convert to 63.
    What's the problem?

    You're assuming that you're working with Ascii values.
    You're actually working with Unicode values.
    When you use getChar() on a String, you get back a 16bit integer, the unicode index. When you do a getBytes() the Unicode values get mapped back to the default codepage of your machine.
    Eg. on an english pc, the default locale is Windows latin, codepage 1252. On non-english pcs, it could be any encoding scheme.
    If you're on a machine set up for a chinese locale, then the Unicode
    values get mapped to your chinese codepage. The extended ascii values,
    above 127 may not be defined in your codepage.
    Try String.getBytes ( "Cp1252" );
    Although I suspect that, whatever you're trying to do, it's probably not the right approach....
    regards,
    Owen

  • Array of Strings?

    How can I make an array of strings?

    or, depending on what the heck you're talkingabout
    That's bad advice now that Java is in version 5.
    The standard loop is the for-each loop. If you don't
    use it you're going down in complexity which is a
    very bad thing according to the "premature
    optimization is evil" bunch. So use for-each if you
    don't want to be accused of "premature optimization"
    by jverd and yawmark and other prominent members of
    that bunch.Thanks for your advice. I use version 1.4.2. I did not intend to give bad advice. My post was targeted at someone who obviously did not understand "nuts and bolts" of java. It was not intended to be a lesson about "good design" or "real life applications" or "standard for loops in version 1.5". I gave an example that i feel is both adequate and appropriate for the target audience. It's intended purpose was to demonstrate very simple and basic concepts to someone who asked a seemingly simple and basic question that could possibly irritate a seasoned programmer like yourself. I have read your helpful posts in this thread and would welcome comments from yawmark and jverd also. I am sure they would be helpful to others who would read this thread in the future but their level of experience (along with Mr Warnerja) would perhaps be lost and uncomprehended by the OP. If in the context of the original question, you believe that my posts and simple examples are inappropriate, then would you kindly explain in terms that the OP can understand? Also explain (in this context) how my posts were wrong and meaningless.
    respectfully yours,
    Arbie

Maybe you are looking for

  • Periodic refresh of Materialized View

    Hi, I am working in a Oracle database for Oracle E-Business Suite. In the database we have a custom materialized view defined as follow: CREATE MATERIALIZED VIEW APPS.XXCUS_NAME_MV <...> BUILD IMMEDIATE REFRESH FORCE ON DEMAND <....> From the below S

  • Mailto: links in Exchange emails

    We utilize a system that sends emails with embedded links to either email an approval or disapproval for requests. Each of these starts with mailto: followed by the mailing address. Prior to upgrading to 3.0 these links worked just fine. Now, with 3.

  • My  iPod second generation 4.2.1 crashes all the time

    Hello, I've got an iPod touch second generation running 4.2.1 but he crashes a lot times. i've got no jailbreak and 1.9GB left. when he crash, he start up again or I see weird things that doesn't have to be there. I tried a soft-reset and restore, wh

  • What's Jsp runtime error?

    Could you tell me what's the matter? Project: C:\Program Files\resin-1.2.10\webapps\BeanToJsp\Anywhere\Anywhere.jpr C:\Program Files\resin-1.2.10\webapps\BeanToJsp\Anywhere\admin.jsp Error: 'class' or 'interface' expected Error: cannot access directo

  • Article sizes and viewer version

    I'm trying to find out where I can see the size of our articles, not the finished folio size and where I can see what viewer version is in the marketplace? I've taken over a project recently and we have the same number of articles as previous edition