Put certain elements of an arraylist of arrays into a hashset

I have an arraylist of arrays. I now need to create a separate list that contains unique combinations of only 3 values contained in the underlying array in the arraylist. I think I can use a HashSet. I am just not sure how to create the HashSet?
I could create an ArrayList of just those 3 values and then use the add method but again I'm not sure how to create the ArrayList based on sub-elements of the original ArrayList. (i.e. copy three "variables" from the array in the arraylist to the new array for each member of the arraylist.)
Any help would be greatly appreciated.

Let us just say I want to. I would prefer a solution to my original problem. Comments asking (well exclamation points are more "demand" then "ask") for justification are irrelevant to my solution. Just work with the problem I have please. Thanks.
Again. I have an arraylist of arrays. I would like to create a nonduplicate subset of only 3 members of the arrays contained in the arraylist. I believe a hashset will do this.
I have tried this as a test..trying to make a hashset of two subelements:
      HashSet hs = new HashSet();
      for (int counter=0; counter<allocations.size(); counter++)
         hs.add({((double[])allocations.get(counter))[1], ((double[])allocations.get(counter))[2]});
      ..but unfortunately I get this error:
mcp.java:227: illegal start of expression
hs.add({((double[])allocations.get(counter))[1], ((double[])allocations.get(counter))[2]});
^
mcp.java:227: ')' expected
hs.add({((double[])allocations.get(counter))[1], ((double[])allocations.get(counter))[2]});
^
so I am obviously not putting the hashset together correctly.

Similar Messages

  • How to create an array in one field and have another field display certain elements from that array?

    I am making a form in Acrobat XI pro.
    In one text field, I created an array of several elements. I want other text fields to display certain elements from that array. For instance, one field should display the 3rd element, another field should display the 13th element, etc.
    The Javascript for making the array is very long, and so I don't want to have to re-calculate the array every single time (in order to reduce rendering time when I open the form on an iPad). This is why I'd like to only have to create the array once, and simply refer to it throughout the form.

    What code are you using to update the array currently? Are you completely rebuiding it when an element changes, or just changing specific elements for certain fields? I'm still not sure what exactly you are trying to do, but something like this in a document level script will create your array:
    var myArray;
    // Call 'updateArray' to initialize array
    updateArray();
    function updateArray() {
         // Code here to create/update array
         myArray = new Array();
         myArray[0] = "Value 1";
         myArray[1] = "Value 2";
         myArray[2] = "Value 3";
    Then, for each field that needs to update this array, you can add a call to 'updateArray()' in the appropriate event. This will rebuild the array completely; if you just want to update specific elements, then you can access them directly.

  • Putting the values of an array into a combobox

    Hey I'm looking for some advice on an error I'm getting
    First heres the program:
    import java.awt.*;
    import javax.swing.*;
    import java.util.*;
    import java.awt.event.*;
    public class Quizgame implements EventListener {
         JPanel mainPanel;
         JFrame theFrame;
         public static void main(String[] args) { Quizgame b = new Quizgame(); b.buildGUI(); }
         public void buildGUI() {
              Quizbook Q = new Quizbook("C:\\Users\\Boab\\Desktop\\JavaRe-sit\\FileInput.txt");
              String question = Q.getContent(0);
              String Ans1= Q.getContent(1);
              String Ans2= Q.getContent(2);
              String Ans3= Q.getContent(3);
              String Ans4= Q.getContent(4);
              theFrame=new JFrame("QuizGame");
              BorderLayout layout = new BorderLayout();
              JPanel background = new JPanel(layout);
              background.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
              Box buttonBox = new Box (BoxLayout.Y_AXIS);
              JButton start = new JButton("Submit");
              start.addActionListener(new MyStartListener());
              buttonBox.add(start);
              JComboBox Answer = new JComboBox(Q);
              start.addActionListener(new MyStartListener());
              buttonBox.add(Answer);
              Box QuestionBox = new Box(BoxLayout.X_AXIS);
              Box nameBox = new Box(BoxLayout.Y_AXIS);
              nameBox.add (new Label(Ans1));
              nameBox.add (new Label(Ans2));
              nameBox.add (new Label(Ans3));
              nameBox.add (new Label(Ans4));
              QuestionBox.add(new Label(question));
              background.add(BorderLayout.EAST, buttonBox);
              background.add(BorderLayout.WEST, nameBox);
              background.add(BorderLayout.NORTH, QuestionBox);
              theFrame.getContentPane().add(background);
              GridLayout grid = new GridLayout(16,16);
              grid.setVgap(1); grid.setHgap(2);
              mainPanel = new JPanel(grid);
              background.add(BorderLayout.CENTER, mainPanel);
              theFrame.setBounds(150,150,1,1); theFrame.pack(); theFrame.setVisible(true);
         public class MyStartListener implements ActionListener {
         public void actionPerformed(ActionEvent a) {
                   //where you put whats to happen
         public class comboListener implements ActionListener {
         public void actionPerformed(ActionEvent a) {
                   //where you put whats to happen
         There is another file which creates an array of strings with the instance Q in this class ^
    I'm trying to fill the combobox with the values of the array but I can't get it too work. With the code as it is now I get:
    C:\Users\Boab\Desktop\Seperate Java files\NewQuiz\Quizgame\Quizgame.java:41: cannot find symbol
    symbol : constructor JComboBox(Quizbook)
    location: class javax.swing.JComboBox
              JComboBox Answer = new JComboBox(Q);
    ^
    1 error
    I don't really understand why it doesn't work, When I look up the error online its about the class but it works fine without the Combobox line. Any ideas why it won't put the array into the combobox?
    Also my next step is to put only certain values into the combobox i.e values 2-4 in the array, Is there any smart piece of code to do this or do I need to put a loop in with an addcontent and hardcode it?
    Thanks for any help

    Yeah sorry, Quizbook is a class with a method to read out the array the method is:
         public String getContent(int element)
              //access arraylist and return
              return (String)Quizbook.get(element);
         so I tried what you said and put :
    JComboBox Answer = new JComboBox(Q.getContent(5));
    Because the Answer is at that location in the array but it gave me the same error message:
    C:\Users\Boab\Desktop\Seperate Java files\NewQuiz\Quizgame\Quizgame.java:41: cannot find symbol
    symbol : constructor JComboBox(java.lang.String)
    location: class javax.swing.JComboBox
              JComboBox Answer = new JComboBox(Q.getContent(3));
    ^
    1 error
    Process completed.
    So I would of thought that meant use the getContent method from Q object with element bieng 3?

  • How can i get all elements from a arraylist

    Hello everyone
    I have an arraylist with 40 elemets inside it.
    I want to be able to get the first 10 elements of the arraylist and put them into a sql statement (I can do this ok) but the problem is when i want to get the next 10 elements (from 10 to 20) they will not execute to the database. is this possible with just one prepared statement?
    thanks
    piper

    Hello Ken this is my code so far, And i keep getting the error
    binary data would be truncated.
    And if i change the values in the for loop i get an exception null.
    I do not know what is wrong with this so could you be so kind as to. help me thaks
    piper
    try {
          String data = "jdbc:odbc:myProject";
                 Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
             Connection conn = DriverManager.getConnection(data,"","");
          int rows=0;
         PreparedStatement ps = conn.prepareStatement(
         "INSERT INTO Ben (Phone,addr1,addr2,PostCode) VALUES (?,?,?,?)");
              Iterator io = arr3.iterator();
                   while (io.hasNext())
                        for (int pos = 1; pos <=4; pos++)
                             String sf = (String)io.next();
                             ps.setString(pos,sf);
                        rows += ps.executeUpdate();
                        System.out.println("inserted" + rows + " rows");
         ps.close();
         return;
            }catch (Exception e1) {
                     System.err.println("Got an exception! ");
                     System.err.println(e1.getMessage());

  • How to only restore only certain elements after reinstall

    Hi guys
    Quick question. My macbook is reeeeally tired, so I've decided to give it a complete reinstall of Snow Leopard. However, I am confused how I should proceed without loosing some vital things.
    Here's the thing!
    I have a complete timemachine backup of my machine but I do not wish to simply restore this entire image. I want a reinstall completely (to get rid of whatever is making my computer slow) and then just pull certain elements from timemachine to the newly installed and fresh OS.
    I this possible? (1) reinstall (2) hook my timemachine drive to the computer (3) selected e.g. apps, musik, docs etc. to restore (i.e. restoring vital elements without getting the bugs back)
    I have tried looking everywhere for this, so it would be for great help if anybody can answer!
    thanks

    That's much more complex that you may think, and is probably overkill anyway.
    Reinstalling apps selectively can be done, but won't work well for complex ones -- if an app comes with it's own Installer, it almost certainly puts other files in other places, in addition to putting the app in your Applications folder. If you don't know what and where all those other files are, and restore them, too, the app probably won't work well, if at all.
    It's usually much better (and safer) to address the problem(s) directly.
    See Baltwo's post: http://discussions.apple.com/thread.jspa?messageID=11853228&#11853228

  • How to shuffle the elements in an ArrayList?

    Hi, everyone
    I write the following method to shuffle the elements of an ArrayList of Question type, and then Print the questions out
    public void shuffle()
            System.out.println ("This is a test created randomly");
            Random generator = new Random ();
            for (int i = 0; i < questions.size(); i++)
                int randomQuestion = generator.nextInt(questions.size());
                Question temp1 = questions.get(i);
                Question temp2 = questions.get(randomQuestion);
                Question temp3 = temp1;
                temp1 = temp2;
                temp2 = temp3;
                System.out.println ("" + (i+1) + ". " + questions.get(randomQuestion).getQuestion()+"\n");  
        }      But I find that the elements of the ArrayList have not been swapped, why?
    Thank you.

    temp1, temp2 and temp3 are all local variables. They're put on the stack at the beginning of the function and popped off at the end. You are never modifying the collection.

  • How to display last element in a dynamic 1d array

    hi..
    i want to display the value of last element in a 1d dynamic array.../ i mean ..if i stop the vi run, i need to display the last element in the array..how can i do this?
    and is there any way to use a button to start the vi...instead of using the Run button on the vi front panel??
    Solved!
    Go to Solution.

    Index array!.  Use array size to determine the size of your array, subtract 1, feed that in the index terminal of Index Array.
    You have to start the VI running somehow.  It could be set to run when opened.  Assuming what you want is a means to type values into a front panel, hit a GO button that you created on the front panel, then have the real part of the VI execute.  You could use an event structure.  Or put a while loop at the beginning with a small wait statement in side that basically just polls the GO button.  When that button is pressed, the true boolean stops the while loop and allows the program to proceed to the main body of your program.

  • Arraylists and arrays

    i'm trying to put the numbers in an arraylist into an int[] array. could anyone tell me how this could be done? i tried the below but i get an error pointing to return divisors.toArray();
    import java.util.ArrayList;
    import java.util.List;
    class FactorsDemo {
        public static void main(String[] args) {
         //for(int i = 10; i < 30; i+=5) {
             int[] divisors = getDivisors(10);
        static int[] getDivisors(int n) {
         List<Integer> divisors = new ArrayList<Integer>();
         for(int d = 1; d <= n/2; d++) {
             if(n%d == 0) divisors.add(new Integer(d));
         return divisors.toArray();
    }

    i'm trying to get this code to compile without using generics, just to see how it is done. it gets the divisors of a number, puts them into an arraylist, and then returns an array with those same divisors.
    i tried to cast the arraylist object to an int, but it's not working.
    can anyone show me what i need to do?
    import java.util.ArrayList;
    import java.util.List;
    class FactorsDemo2 {
        public static void main(String[] args) {
         for(int i = 10; i < 50; i+=5) {
             System.out.print("Factors of "+i+": ");
             int[] divisors = getDivisors(i);
             display(divisors);
        static int[] getDivisors(int n) {
         List divisors = new ArrayList();
         for(int d = 1; d <= n/2; d++) {
             if(n%d == 0) divisors.add(new Integer(d));
         int[] myInts = new int[divisors.size()];
            for(int i = 0; i < divisors.size(); i++) {
                   myInts[i] = (int) divisors.get(i);
            return myInts;
        static void display(int[] x) {
         for(int i = 0; i < x.length; i++) {
             System.out.print(x[i]+" ");
         System.out.println();
    }FactorsDemo2.java:21: inconvertible types
    found : java.lang.Object
    required: int
    myInts[i] = (int) divisors.get(i);
    ^
    Note: FactorsDemo2.java uses unchecked or unsafe operations.
    Note: Recompile with -Xlint:unchecked for details.
    1 error

  • Does anybody know why when I aTrying to edit my yahoo profile using Firefox certain elements do not show up such as update "Load Photo" on the avatar page.

    Trying to edit my yahoo profile using Firefox and certain elements do not show up such as update "Load Photo" on the avatar page.
    If I use Explorer it allows me to see all the links and can edit my profile but not in Firefox.
    I am not sure the URL will let you in as is a private link.

    '''Try the Firefox SafeMode''' to see how it works there. <br />
    ''A troubleshooting mode, which disables most Add-ons.'' <br />
    ''(If you're not using it, switch to the Default Theme.)''
    * You can open the Firefox 4.0+ SafeMode by holding the '''Shft''' key when you use the Firefox desktop or Start menu shortcut.
    * Or use the Help menu item, click on '''Restart with Add-ons Disabled...''' while Firefox is running. <br />
    ''Don't select anything right now, just use "Continue in SafeMode."''
    ''To exit the Firefox Safe Mode, just close Firefox and wait a few seconds before using the Firefox shortcut (without the Shft key) to open it again.''
    '''''If it is good in the Firefox SafeMode''''', your problem is probably caused by an extension, and you need to figure out which one. <br />
    http://support.mozilla.com/en-US/kb/troubleshooting+extensions+and+themes
    ''When you figure out what is causing that, please let us know. It might help other user's who have that problem.''

  • Reading XML file and skip certain elements/attributes??

    Hi folks!
    Suppose I have a XML file looking like this:
    <?xml version="1.0" encoding="ISO-8859-1"?>
    <!DOCTYPE dvds SYSTEM "DTDtest.dtd">
    <dvds>
    <dvd>
    <title>
    Aliens
    </title>
    <director>
    James Cameron
    </director>
    <format>
    1.85:1
    </format>
    </dvd>
    <dvd>
    <title>
    X-Men
    </title>
    <director>
    Bryan Singer
    </director>
    <format>
    2.35:1
    </format>
    </dvd>
    </dvds>
    In my Java application I want to read this XML file and print it on the screen (including all tags etc). So far, so good. BUT, if I want to skip certain elements, i.e. all information about the dvd 'X-Men', how am I supposed to do this? In other words, I would like my app to skip reading all information about X-Men and continue with the next <dvd>... </dvd> tag. Is this possible?
    My code so far is from the XML tutorial from Sun and it looks like this:
    import java.io.*;
    import org.xml.sax.*;
    import org.xml.sax.helpers.DefaultHandler;
    import javax.xml.parsers.SAXParserFactory;
    import javax.xml.parsers.ParserConfigurationException;
    import javax.xml.parsers.SAXParser;
    public class MyXML extends DefaultHandler
    public static void main(String argv[]) {
    if (argv.length != 1) {
    System.err.println("Usage: cmd filename");
    System.exit(1);
    // Use an instance of ourselves as the SAX event handler
    DefaultHandler handler = new MyXML();
    // Use the default (non-validating) parser
    SAXParserFactory factory = SAXParserFactory.newInstance();
    try {
    // Set up output stream
    out = new OutputStreamWriter(System.out, "UTF8");
    // Parse the input
    SAXParser saxParser = factory.newSAXParser();
    saxParser.parse( new File(argv[0]), handler);
    } catch (Throwable t) {
    t.printStackTrace();
    System.exit(0);
    static private Writer out;
    //===========================================================
    // SAX DocumentHandler methods
    //===========================================================
    public void startDocument()
    throws SAXException
    emit("<?xml version='1.0' encoding='UTF-8'?>");
    nl();
    public void endDocument()
    throws SAXException
    try {
    nl();
    out.flush();
    } catch (IOException e) {
    throw new SAXException("I/O error", e);
    * <p>This method prints the start elements including attr.
    * @param namespaceURI
    * @param lName
    * @param qName
    * @param attrs
    * @throws SAXException
    public void startElement(String namespaceURI,
    String lName, // local name
    String qName, // qualified name
    Attributes attrs)
    throws SAXException
    String eName = lName; // element name
    if ("".equals(eName)) eName = qName; // namespaceAware = false
    emit("<"+eName);
    if (attrs != null) {
    for (int i = 0; i < attrs.getLength(); i++) {
    String aName = attrs.getLocalName(i); // Attr name
    if ("".equals(aName)) aName = attrs.getQName(i);
    emit(" ");
    emit(aName+"=\""+attrs.getValue(i)+"\"");
    emit(">");
    public void endElement(String namespaceURI,
    String sName, // simple name
    String qName // qualified name
    throws SAXException
    emit("</"+qName+">");
    * <p>This method prints the data between 'tags'
    * @param buf
    * @param offset
    * @param len
    * @throws SAXException
    public void characters(char buf[], int offset, int len)
    throws SAXException
    String s = new String(buf, offset, len);
    emit(s);
    //===========================================================
    // Utility Methods ...
    //===========================================================
    // Wrap I/O exceptions in SAX exceptions, to
    // suit handler signature requirements
    private void emit(String s)
    throws SAXException
    try {
    out.write(s);
    out.flush();
    } catch (IOException e) {
    throw new SAXException("I/O error", e);
    // Start a new line
    private void nl()
    throws SAXException
    String lineEnd = System.getProperty("line.separator");
    try {
    out.write(lineEnd);
    } catch (IOException e) {
    throw new SAXException("I/O error", e);
    Sorry about the long listing... :)
    Best regards
    /Paul

    A possibility that comes to mind is to create an XSLT script to do whatever it is you want - and call it from inside the program. The XSLT script can be stashed inside your .jar file by using getClass().getClassLoader().getResource("...")
    - David

  • How to bind an element in an arrayList to a table column

    Hi everyone, I need your help.
    I have an ObjectListDataProvider to bind a class MyClass to a table. Inside of MyClass, there is a property called dynNumOfElements of type ArrayList. I need dynamically create the columns of the table to match the number of elements in ArrayList, and bind each element in the ArrayList to a column.
    However I dont know how to do it? It is going to be something like createValueBinding("#{currentRow.value(['dynNumOfElements[1]']}"). Obviously this does not work.
    Can you tell me a way to solve this problem?
    Is it possible to bind a column to an element in a collection?
    Thanks in advance

    Thanks Winston,
    Following is what I did. They are all in Page1.jsp
    public String getMyData(){
    // Make sure to check for nulls
    return myList.get(count++).toString();
    private ArrayList myList = new ArrayList();
    private int count = 0;
    public String button3_action() {
    // TODO: Replace with your code
    //initialize list
    myList.add("string 1");
    myList.add("Stirng 2");
    myList.add("string 3");
    TableColumn tc1 = new TableColumn();
    tc1.setId("tc1");
    tc1.setHeaderText("tc1");
    tableRowGroup2.getChildren().add(tc1);
    StaticText st1 = new StaticText();
    st1.setValueBinding("text", getApplication().createValueBinding("#{Page1.myData}"));
    tc1.getChildren().add(st1);
    return null;
    The error message is "Error getting property 'getMyData' from bean of type helloweb.Page1"
    Can you help me to fix the problem? Thanks a lot.

  • Set number of elements in a two dimensional array

    Hi,
    Does anyone know how to set the number of elements in a two dimensional array directly in teststand.
    To set a one dimsional array is simple:
    SetNumElements( locals.somearray,4)
    Is there a method to do this for a two dimensional array?
    Sean

    From the help file (TestStand 4.2.0):
    PropertyObject.SetNumElements
    SetNumElements Method
    Syntax
    PropertyObject.SetNumElements ( numElements, options = 0)
    Purpose
    Sets the number of elements of a single dimensional array.
    Remarks
    This method is only valid for single dimensional arrays. The elements in the array retain their values. Use the PropertyObjectType.ArrayDimensions property to set the number of elements in each dimension of a multi-dimensional array.
    Parameters
    numElements As Long
    [In] New number of elements for the array.
    options As Long
    [In] Pass 0 to specify the default behavior, or pass one or more PropertyOptions constants. Use the bitwise-OR operator to specify multiple options.
    This parameter has a default value of 0.
    So you could use, for example: Locals.MultidimensionalArray.Type.ArrayDimensions.SetBounds({1,0},{3,4}) to set an array to have three dimensions (1,2,3), each with five elements (0,1,2,3,4).

  • 1. How do I add CSS effects to a certain element?

    How do I add CSS effects to a certain element?
    There are several effects (like customized hover effects) that I could with CSS. I want to know how do I add the CSS effects for a certain element/object from within Edge animate.

    The way to add css in general is
    sym.$('element').css({
    'Property':'value',
    'Property':'value',
    'Property':'value'

  • Put certain e-mails on a CD for files to save

    Hi:
    I am trying to put certain e-mails (incoming & sent) onto
    a CD to burn.
    I tried to drag and Drop but they will not be accepted by the CD.
    I do not see anything obvious in any of the header items.
    thanks,
    Greg

    Hi Greg.
    Not sure whether this is what you want, but you can do File > Save As. Choose Raw Message Source as the format if you want to be able to import them back into Mail or any other mail client.

  • How to put flash as a table or cell background or put HTML elements on top of flash file?

    Hi Guys,
    Could anyone please suggest me that how to put flash file as a table or cell background. I want to design a website and want to put HTML elements like table, images, text on top of flash file. so its look like animation in background. please visit following websites for an example: http://www.gagudju-dreaming.com/ and http://disneyworld.disney.go.com/
    Please guide me ASAP, thanks a lot in advance.
    Nitz.

    Hi Nitz
    The first thing you must do is convert your layout from table based to css based, (tables are o/k for tabular data, but not layout) but if you have never used css for layout it may be a steep learning curve.
    My recommendation is to start with the following tutorial on converting a table based comp to a css layout -
    http://www.adobe.com/devnet/dreamweaver/articles/dw_fw_css_pt1.html
    More info on using css is available here - http://www.adobe.com/devnet/dreamweaver/css.html.
    Once you have converted your site the 'procedure' for using swf's as a background, (does not work well with flv's, but can be done using html5 video without a skin, to a limited extent) is the same as having a background-image resize automatically to the full browser view-port. The best way to learn how to do this is to view the code on a page using the background-image technique, view the code on this page - http://www.pziecina.com/indexold.php.
    However, instead of having a fluid layout I would recommend using a fixed layout size to start with, as this overcomes many problems. I have uploaded a basic test page to illustrate the idea to - http://www.pziecina.com/test_ideas/swfbg_test.html. As I said the page must be resized in this example in order to see the effect, (so do not forget to resize the browser, even if it is only by 1px), but if you use a fixed size layout and your swf's size fits the desired area correctly the resize should not be required.
    PZ
    www.pziecina.com

Maybe you are looking for

  • Error while installing Extension Builder 3 in Eclipse

    Hi, While installing the extension builder 3.0 zip which was downloaded from pre release forum in eclipse 4.1 there is an error comming Cannot complete the install because one or more required items could not be found.   Software being installed: Ado

  • RecordSet and Command Window bigger?

    A big problem in older DW version where the small an unresizeable windows for adding recordsets and commands. And now i have to figure out, that this problem still exists in dw cs3. Really - i thought dw cs3 is also made for bigger website! But they

  • SQL *NET Add-On

    I want to install the Personnel Oracle 8 (Student Edition) with SQL *NET Add-On Version 2.2.2.1.1 on Windows 95(win98), but the system tell me that i have to install the SQL *NET Add-On version 2.2.2.0.0 (patch) first. Anybody can help me ? Thanks Be

  • Testing wireless access points

    I have been deploying Cisco (as well as Aruba and HP) wireless in the enterprise/education for some time.  One of the selling points of the Cisco model IMHO is the ability to do agressive load balancing.  I have been asked to test a smaller venders e

  • Flip 4 Mac error

    When I try to enter my name and serial number in Sustem Prefs I get an error: There has been an Internal Error Engine not installed. I have re-installed etc - any ideas?