Pass an arrayList into a method

I am looking to pass and  arraylist into a method and I am wondering how this is done...

I figured it out:
public function someMethod(someArray:ArrayList){}
I figured it was the same.
This is dealing with flex, How ever on the AS side, so its a pure AS question

Similar Messages

  • How to call a java method so I can pass a file into the method

    I want to pass a file into a java method method from the main method. Can anyone give me some help as to how I pass the file into the method - do I pass the file name ? are there any special points I need to put in the methods signature etc ?
    FileReader file = new FileReader("Scores");
    BufferedReader infile = new BufferedReader(file);
    Where am I supposed to put the above text - in the main method or the one I want to pass the file into to?
    Thanks

    It's a matter of personal preference really. I would encapsulate all of the file-parsing logic in a separate class that implements an interface so that if in the future you want to start taking the integers from another source, e.g. a db, you wouldn't need to drastically alter your main application code. Probably something like this, (with an assumption that the numbers are delimited by a comma and a realisation that my file-handling routine sucks):
    public class MyApp{
    public static void main(String[] args){
    IntegerGather g = new FileIntegerGatherer();
    Integer[] result = g.getIntegers(args[0]);
    public interface IntegerGatherer{
    public Integer[] getIntegers(String location);
    import java.io.*;
    public class FileIntegerGatherer implements IntegerGatherer{
    public Integer[] getIntegers(String location){
    FileInputStream fs=null;
    try{
    File f = new File(location);
    fs = new FileInputStream(f);
    byte[] in = new byte[1024];
    StringBuffer sb = new StringBuffer();
    while((fs.read(in))!=-1){
    sb.append(new String(in));
    StringTokenizer st = new StringTokenizer(sb.toString(),",");
    Integer[] result = new Integer[st.countTokens()];
    int count = 0;
    while(st.hasMoreTokens()){
    result[count]=Integer.valueOf(st.nextToken());
    count++;
    catch(IOException e){
    //something sensible here
    finally{
    if(fs!=null){
    try{
    fs.close();
    catch(IOException f){
    return result;
    Once compiled you could invoke it as java MyApp c:\myInts.txt
    Sorry if there are typos in there, I don't have an ide open ;->

  • How to pass java arraylist into javascript arrays

    Hi, i have declare an arraylist
    ArrayList list1 = new ArrayList();Inside the arraylist, there are elements. Now, i wan to pass the elements in the java arraylist into javascript arrays but i encounter javascript errors.
    This is how i code.
    var arr1 = new Array();
    <%
    for ( int x =0; x<list1.size(); x++)
    %>
         arr1[<%=x%>] = <%=(String)list1.get(x)%>;
    <%
    %>how do i solve this problem?
    Thanks for the guidance in advance

    JTech wrote:
    Hi,
    Use Quotes around string value ( arr1[indexposition] = "stringvalue";), when assign to javascript array as below.
    arr1[<%=x%>] = "<%=(String)list1.get(x)%>"; Regards,
    Ram.Hi Ram,
    How about using arr1 = <%=list.toArray()%> ??? Is this possible? I tried it but was not working on my IDE. Do you have any solutions for this??
    Regards,
    Thiagu

  • How do u pass an object into a method

    I want to create a method getData that takes an object of type Helper and returns an object of the same type.
    how do u pass objects into a method and how do u get objects as returns im a bit confused

    That will just allow you to pass a parameter. If you want to return a helper object
    Helper paramHelper = new Helper();
    Helper someHelper = callMethod(paramHelper);
    public Helper callMethod(Helper hobj) {
        //<some code>
        Helper retHelper = new Helper();
        //<blah, blah>
        return retHelper;

  • Passing polymorphic ArrayLists to a method expecting ArrayList superclass

    In short, is it possible? In keeping in line with my other threads and a program using cats, I give you this example using Cats and Animals (a cat is an animal):
    public void go()
         ArrayList<Cat> lotsOfCats = new ArrayList<Cat>();
         feed(lotsOfCats);
    void feed(ArrayList<Animal> animals)
         //feed the animals
    }So an error is thrown because the function is expecting an ArrayList of Animals and I'm trying to pass in an ArrayList of Cats. The function shouldn't have any problem dealing with the cats though because a cat IS AN Animal, so anything you can do to/find out about the superclass animal you can certainly apply to a cat. I've tried casting the lotsOfCats ArrayList like so:
    ArrayList<Animal> myAnimals = (ArrayList<Animal>)lotsOfCats;But it didn't work. So is there any way for me to reference the ArrayList as type Animal without necessarily having to originally declare it that type? Or do I just have to suck it up and declare it type Animal from the get go?

    Thank you both for the responses. I gave you both helpful ratings because I think you both answered the question, just in different ways. fredrikl, your solution certainly works well. I'm sure I have seen that notation in documentation and such but haven't had experience using it yet. Your solution works out perfectly for my method since all I am trying to do is print out array components with it. I see you said you can't add components, that makes sense since the ArrayList doesn't really know what it is, but I figure you can still modify existing things in the list, right? Didn't actually try it yet but I have been using some casts to get out various things for display and that's working fine.
    morgalr, that's a complicated piece of code you have there. I don't fully understand it yet but I'll go through it again if I get this problem. From what I gather, it looks like you actually tried to solve my original problem and successfully did it?

  • Passing the array into actionPerformed method

    Hi friends! I am new at java. I made a tictactoe game board with GUI and it is designed according to nxn (desired any n value). When I pressed to any button, it should write an X to my board but I could not passed the button's action. My problem is that my actionPerformed method does not accept array button[j]. In the below there is a part of my code :
    for(int j=0;j<button.length;j++)     // adding the buttons
    button[j].addActionListener(this);
    public void actionPerformed(ActonEvent evt)
    // what can I read here for detecting the right button? button length is changable, it is depent on what we desire at first.
    // I tried this code in this area but it does not work:
    // if (evt.getSource()==button[j])
    // button[j].setText("X");
    // normally, it works if I write every button individually like that:
    // button1.addActionListener(this); (same for other buttons)
    // public void actionPerformed (ActionPerformed evt)
    // if (evt.getSource()==button1)
    // button1.setText("X"); (same code for other buttons)
    // but I want to make a generalized board action
    }I will be appreciated with your helps...
    Musty

    Hi musty4284,
    The getSource method of ActionEvent(not ActonEvent) returns an object and the way you're comparing objects is wrong.
    Theorically, you should do something like this :
    public void actionPerformed(ActionEvent evt) {
        JButton b = (JButton) evt.getSource();
        if ( button[j].equals(b) ) {
    }Edit :
    When using a listener for an array of JButton, it is a good idea to give a unique identifier to each button (for example, their index in the array). The JButton class has a setName method not to confuse with the setText method.
    While building your array of JButton, you can do :
    JButton[] button = new JButton[9];
    for (int i = 0; i < 9; i++) {
        button[i] = new JButton();
        button.setName(i);
    While handling the event :public void actionPerformed(ActionEvent evt) {
    JButton b = (JButton) evt.getSource();
    int index = Integer.parseInt(b.getName());
    button[index].setText("X");
    Edited by: Chicon on Oct 4, 2009 11:20 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

  • How to pass a file into a java method

    I am trying to pass a file into a java method so I can read the file from inside the method. How can I do this? I am confident passing int, char, arrays etc into methods as I know how to identify them in a methods signature but I have no idea how to decalre a file in a mthods signature. Any ideas please ?
    Thanks

    Hi,
    Just go thru the URL,
    http://www6.software.ibm.com/devtools/news1001/art24.htm#toc2
    I hope you will get a fair understanding of 'what is pass by reference/value'.
    You can pass Object reference as an argument.
    What Pablo Lucien had written is right. But the ideal situation is if you are not modifying the
    file in the calling method, then you can pass the String (file name) as an argument to the called method.
    Sudha

  • Pass parameters into a method from other methods.

    I m testing  2 related applications with coded ui test and wanna pass a parameter from one method into another.
    how can i do that?
    Thank you in advance.

    Hi mah ta,
    Could you please tell us what about this problem now?
    If you have been solved the issue, would you mind sharing us the solution here? So it would be helpful for other members who get the same issue.
    If not, please let us know the latest information about it.
    Best Regards,
    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click
    HERE to participate the survey.

  • Pass Structured table into dynamic table parameter in public method

    Ladies and Gentlemen,
    I have a requiremet to pass (1 at a time) any number of tables into a reuseable method in a custom class.  The Method code is as follows:
    method CREATE_OUTBOUND_FILE.
    * Importing VALUE( IV_PATHNAME )  TYPE PATHEXTERN File Destination
    * Importing VALUE( IT_FILE_RECORD ) TYPE REF TO DATA  Table with Output
    * Importing VALUE( IV_RECORD_STRUCTURE )  TYPE STRING OPTIONAL  Record Structure
    * Importing VALUE( IV_DELIMITER )     TYPE STRING     File Delimiter
    * Exporting VALUE( EV_RECORD_CNT )  TYPE STRING Record Count
      Data:
            ls_line_cnt(6) type n,
            lt_data_struc  type zty_ddic_struc_T,
            ls_string      type string.
      field-SYMBOLS: <fs_string> type any.
    * Open Dataset for outputting file details
      Open dataset iv_pathname for output in text mode encoding default.
      Assign ls_string to <fs_string> CASTING TYPE (iv_record_structure).
      loop at it_file_record into <fs_string>.
        transfer <fs_string> to iv_pathname.
        Add 1 to ls_line_cnt.
        clear <fs_string>.
      endloop.
      ev_record_cnt = ls_line_cnt.
    where IV_PATHNAME = output destination & filename
                IT_FILE_REC     = data table
                IV_RECORD_STRUCTURE = is ddic structure definition for the data table
                IV_DELIMITER = file delimiter, in this case, let's say it's C (for CSV)
         and EV_RECORD_CNT is a count of numbe of records processed.
    Lets say, for example, I wish to load data from table SFLIGHT into the method when program A is executed.  Then another time I wish to excute Program B which is passing in data of table  SFLCONN2.  I hope that by using the "type ref to data" defintion, I can pass the table contents through. Is this true?
    Secondly, I'm getting a syntax error saying that "IT_FILE_RECORD" is not defined as a table (and therefore can't be looped at), and therefore can't be read.  How can I access the data in this table in preparation for output.
    Any assistance or thoughts would be greatly appreciated.
    Regards,
    Steve

    Hi Stephen ,
    Graham already gve part of the solution.
    If you declare
    Importing VALUE( IT_FILE_RECORD ) TYPE REF TO DATA
    it does not make sense to declare to pass by VALUE because you will not change this refernce in the method. Calling this method, you must pass a refefernce.
    data:
      lr_ref type ref to data.
    get reference of <your itab here> into lr_ref.
    CREATE_OUTBOUND_FILE( ...IT_FILE_RECORD = lr_ref ... )
    In the method, it goes as graham explained.
    Anyway, I would declare the table parameter as
    Importing IT_FILE_RECORD TYPE TABLE
    The your code could work, but you will have troube with any non-character fields in the tables.
    Regards,
    Clemens

  • How can I move an ArrayList from one method to another?

    As the subject reveals, I want to know how I move an ArrayList. In one method, I fill my ArrayList with objects, and in the next I want to pick an arbitrary object out of the ArrayList.
    How do I make this work??

    You pass the same array list to both the method. Both method are getting the same thing.
    void main(){
    //create array list here
    ArrayList aList = new ArrayList();
    //pass it to a method to fill items
    fillArrayList(aList);
    //pass the same arraylist to another method
    printArrayList(aList);
    void fillArrayList(ArrayList list){
      list.add("A");
    void printArrayList(ArrayList list){
    //The array list will contain A added by the previos method
    System.out.println(list);
    FeedFeeds : http://www.feedfeeds.com                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • How can i pass a parameter into paintComponent()?

    public void paintComponent(Graphics g)
    Graphics2D g2 = (Graphics2D) g;
              for(int i = 150;i<=250;i+=20)
                   for(int a = 50;a<=200;a+=50)
              Rectangle box = new Rectangle(i, a, 15, 15);
    g2.draw(box);
    this is my paintComponent method. as far as i'm concerned, all our codings for drawing must be inside this method rite? My assignment is to create something like a cinema ticket system where we will display all the seats then user enters a position then we mark it. when i prompt the user for the position..how do i pass it into this method? pls help me. obviously the coding to prompt is in another .java file.

    //this is my main
    public class AirAsia extends JComponent {
              static JLabel input, input2;
         private static void test(){
              JFrame frame = new JFrame("Aeroplane Seating");
              frame.setSize(500,500);
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
              frame.setVisible(true);
              String prompt = JOptionPane.showInputDialog("Enter x");
         input = new JLabel("You have entered " +prompt);     
    String prompt 2= JOptionPane.showInputDialog("Enter x");
         input 2= new JLabel("You have entered " +prompt2);     
              RectangleComponent component = new RectangleComponent();
    frame.add(component);
              frame.setVisible(true);
    private static void createAndShowGUI()
         JFrame.setDefaultLookAndFeelDecorated(true);
              test();
    public static void main(String[] args)
    createAndShowGUI();
    //now this is my paint component in another file
    public class RectangleComponent extends JComponent
    public void paintComponent(Graphics g)
    Graphics2D g2 = (Graphics2D) g;
              for(int i = 150;i<=250;i+=20)
                   for(int a = 50;a<=200;a+=50)
              Rectangle box = new Rectangle(i, a, 15, 15);
    g2.draw(box);}
              for(int i = 60;i<=160;i+=20)
                   for(int a = 240;a<=820;a+=15)
              Rectangle box = new Rectangle(i, a, 15, 15);
    g2.draw(box);
    first of all, i ask the user to enter 2 inputs which are x and y. so now how do i pass in the x and y into paint component method so i can mark/draw the box?

  • How to pass a variable into a cfc?

    prior to calling the cfinvoke, I have coding that determins a
    variable "X"
    I need to pass X into a cfc so it can complete the query held
    there.
    So I tried
    <cfinvoke component="A"
    method="AList"
    returnvariable="AResults">
    <cfinvokeargument name="x" value="#X#"
    /></cfinvoke>
    correct so far?
    Now over on the cfc page is where I'm getting stuck
    Inside my cffunction I'm adding <cfargument name="X" />
    But how do I get the value in?

    I don't quite understand your question. Can you rephrase?
    But before all that, bear in mind that one doesn't pass a
    variables into a
    *CFC*, one passes it into a function within the CFC. And as
    with all
    functions, one passes values into the function by passing it
    as an
    argument. But - of course - the function has to be coded to
    expect the
    argument.
    Your own sample code demonstrates this in action:
    <cfinvokeargument name="abbrCode"
    value="#companyAbbrCode#" />
    (NB: lose the trailing slash: this is CFML, not XML).
    So you know how to do that.
    Hence me not quite understanding what you're actually asking.
    Adam

  • How to pass table to in a method as a parameter

    Hi
    I need to pass one table in one method to another method as a parameter.
    ex: it_tab type zvalue(DDIC).
         send_mail( it_tab)like this i need to pass. How to do this.
    Please help me.
    Thanks & Regards
    SUN

    Hello,
    You'll need a table category that has the same structure of your internal table. Suppose you need to pass an internal table of type SCARR: you'll actually pass a parameter of type SCARR_TAB (look for it into tcode SE11).
    Remember that in a OOP scope, you cannot have header line in your internal tables.
    Regards,
    Andre

  • How to change elements in ArrayList into String

    Greetings,
    i like to change elements in arrayList into string.
    This is how i declare an ArrayList in a Java file
    ArrayList listing = new ArrayList();below is just a simple example of how i insert the string into the arraylist
    String concat = "';
    concat = concat + "apple";
    //Transfer the concat string into arraylist
    listing.add(concat);
    return listing;
    {code}
    On my Jsp page, it will receive the ArrayList from the java file. Lets say the Arrayist is pass into my JSP arraylist
    This is my JSP arraylist
    {code}ArrayList optLists = new ArrayList();{code}
    Inside the arraylist element, it holds data eg: *308577;;RS | [CAT 2] Level: Arena, Section: A02* with a pipe between RS and CAT 2.
    Now i looping the arraylist
    {code}int a = 0;
         for ( a=0; a < optLists.size(); a++)
              String tempString = "";
              String splitTemp = "";
                     String tempString = (String)optLists.get(a);
              splitTemp =  tempString.split("|");
              System.out.println("Split String Results: "+ splitTemp);
         {code}}
    Heres the error:
    *SeatAvailable_jsp.java:560: incompatible types*
        *[javac] found   : java.lang.String[]*
        *[javac] required: java.lang.String*
        *[javac]             splitTemp =  tempString.split("|");*
        *[javac]*       
    What can i do to solve the problem?
    Edited by: leeChaolan on May 2, 2008 4:45 AM
    Edited by: leeChaolan on May 2, 2008 4:48 AM                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

    paternostro is right, you are returning an array into a string which is wrong
    but try this, i haven't tested it though..
    nt a = 0;
         for ( a=0; a < optLists.size(); a++)
              String tempString = "";
              String splitTemp = "";
                     String tempString = (String)optLists.get(a);
              String[] splitTemp =  tempString.split("|");
              for(String xyz : splitTemp)
                   System.out.println("Split String Results: "+ xyz);
         }Edited by: linker on May 2, 2008 1:17 PM
    Edited by: linker on May 2, 2008 1:18 PM

  • Passing formatted HTML into JOptionPane.showMessageDialog()

    I'm attempting to display a message dialog that contains text that is formatted as HTML. The examples I've looked up online show that you can indeed create a string that begins with the tag <html> and pass that string into most swing text components.
    Such as:
    String htmlString = "<html><b>This is a bold string</b>";
    JOptionPane.showMessageDialog(htmlString, ...);I want to do the same thing, but have my HTML stored in a seperate file. I tried using file IO to read in the html one line at a time, and append it into a StringBuffer. Then passing my buffer.toString() into showMessageDialog(). ..It's still not showing my HTML (although it does compile fine).
    Before I start digging into this deep, I just wanted to ask if there was a better solution for accomplishing what I'm trying to do here. Perhaps using a different component or something? I appreciate it.

    (shrugs) Both these examples seem to render the HTML OK, the first is a String provided to a JLabel, the second is an URL provided to a JEditorPane. I included the second to show a Swing component rendering HTML from an external source.
    import java.awt.Dimension;
    import javax.swing.JOptionPane;
    import javax.swing.JEditorPane;
    import java.net.URL;
    class TestHtmlRendering {
      public static void main(String[] args) throws Exception {
        // default for a String in a JLabel is bold,
        // so let's add some emphasis..
        String content =
          "<html><b>This is a bold, " +
          "<em>emphatic</em> string!</b>";
        JOptionPane.showMessageDialog(null, content);
        // styled HTML from http://pscode.org/test/docload/
        URL url = new URL(
          "http://pscode.org/test/docload/trusted.html");
        JEditorPane jep = new JEditorPane(url);
        jep.setPreferredSize(new Dimension(300,200));
        JOptionPane.showMessageDialog(null, jep);
    }I'd say the problem is in the code you did not show, though even the code you did show, was nonsense (show me the URL to the JavaDocs of any showMessageDialog() method that will accept a String as the first argument). For those reasons (and more), I recommend preparing an SSCCE that shows the problem. It is a little harder to prepare an SSCCE involving external files, though if you can demonstrate it using an URL (like above) that solves the problem.

Maybe you are looking for

  • SHOW DECIMAL VALUES IN QUERY

    Hi, I would like to show the decimal values of a calculated keyfigure when i execute the query. Heres whats happening: Base Price * Qty = XXXXX 11*2.6=28.6 bur when i execute the query it shows 29 as the answer, its rounding it off. How can i fix thi

  • Can't restore volume

    When I originally installed 10.3 on my G4 PowerMac, I figured, since it was based on the Unix OS, I'd install the Unix File System, assuming there would be advantages. After a few years of frustration with never being able to stream video clips from

  • Adobe reader for iPad disappointed me

    I cant beleive it, Forms, links, bottoms- don't work with Adobe reader for ipad. ¿Why?

  • Double clicking a list item

    Hi, I'm just trying to perform an action by double-clicking a list item, but doesn't seem to work. code: WHEN-MOUSE-DOUBLE-CLICK trigger on List item (TList). DECLARE v_verwalten VARCHAR2(40); BEGIN v_verwalten := :CONTROL.LIST; IF v_verwalten = 'Cod

  • Déblocage de l"Iphone 4s

    j"ai un Iphone 4s bloqué, souhaitant son déblocage, que pui je faire