SET into string array using toArray()

I have a object java.util.Set collection and I want to convert all the elements
into a string array but i don't know why it is not working in my JSP page...
as i am trying to use toArray() method
i have tried this          
String[]  arr = collection.toArray();this
String[]  arr = (String []) collection.toArray();could you please tell me the right way to aplly it...
thanks in advance....:)

I am using session listener which map sessions and it stores sessionid which i hope is a string
when i directly print this set object it shows
[ED0EF456BD1EE956A069340633C8DB87,UT0EF456BD1EE956A069340633C8DB34,RD0EF456BD1EE956A069340633C8DB98]
Message was edited by:
hunterzz

Similar Messages

  • Splitting html ul tags and their content into string arrays using regular expression

    <ul data-role="listview" data-filter="true" data-inset="true">
    <li data-role="list-divider"></li><li><a href="#"><h3>
    my title
    </h3><p><strong></strong></p></a></li>
    </ul>
    <ul data-role="listview" data-filter="true" data-inset="true">
    <li data-role="list-divider"></li><li>test.</li>
    </ul>
    I need to be able to slip this html into two arrays hold the entire <ul></ul> tag. Please help.
    Thanks.

    Hi friend.
    This forum is to discuss problems of C# development. Your question is not related to the topic of this forum.
    You'll need to post it in the dedicated Archived Forums N-R  > Regular Expressions
     for better support. Thanks for understanding.
    Best Regards,
    Kristin

  • Trying to compare string array using equals not working

    Hi,
    im prolly being really dumb here, but i am trying to compare 2 string arrays using the following code:
    if(array.equals(copymearray))
    System.out.println("they match");
    else
    {System.out.println("dont match");}
    the trouble is that even though they do match i keep getting dont match, can anyone tell me why?

    try
    if (Arrays.equals(array, copymearray))
    System.out.println("they match");
    else
    {System.out.println("dont match");}

  • Search given string array and replace with another string array using Regex

    Hi All,
    I want to search the given string array and replace with another string array using regex in java
    for example,
    String news = "If you wish to search for any of these characters, they must be preceded by the character to be interpreted"
    String fromValue[] = {"you", "search", "for", "any"}
    String toValue[] = {"me", "dont search", "never", "trip"}
    so the string "you" needs to be converted to "me" i.e you --> me. Similarly
    you --> me
    search --> don't search
    for --> never
    any --> trip
    I want a SINGLE Regular Expression with search and replaces and returns a SINGLE String after replacing all.
    I don't like to iterate one by one and applying regex for each from and to value. Instead i want to iterate the array and form a SINGLE Regulare expression and use to replace the contents of the Entire String.
    One Single regular expression which matches the pattern and solve the issue.
    the output should be as:
    If me wish to don't search never trip etc...,
    Please help me to resolve this.
    Thanks In Advance,
    Kathir

    As stated, no, it can't be done. But that doesn't mean you have to make a separate pass over the input for each word you want to replace. You can employ a regex that matches any word, then use the lower-level Matcher methods to replace the word or not depending on what was matched. Here's an example: import java.util.*;
    import java.util.regex.*;
    public class Test
      static final List<String> oldWords =
          Arrays.asList("you", "search", "for", "any");
      static final List<String> newWords =
          Arrays.asList("me", "dont search", "never", "trip");
      public static void main(String[] args) throws Exception
        String str = "If you wish to search for any of these characters, "
            + "they must be preceded by the character to be interpreted";
        System.out.println(doReplace(str));
      public static String doReplace(String str)
        Pattern p = Pattern.compile("\\b\\w+\\b");
        Matcher m = p.matcher(str);
        StringBuffer sb = new StringBuffer();
        while (m.find())
          int pos = oldWords.indexOf(m.group());
          if (pos > -1)
            m.appendReplacement(sb, "");
            sb.append(newWords.get(pos));
        m.appendTail(sb);
        return sb.toString();
    } This is just a demonstration of the technique; a real-world solution would require a more complicated regex, and I would probably use a Map instead of the two Lists (or arrays).

  • Storing a record set into an array

    Hello Again,
    Yet another road block in my destination to completing my program. I wanted to create a MultiColumn Combobox and needed to store my Database values into an array so I get get them into the Combobox. I'm having trouble getting this code to work properly. It seems that the the combobox wont accept the variable items maybe because it is outside the scope? I tried to move the code around to get it to work but it don't.
    here is the code.
    package pms;
    import java.awt.*;
    import javax.swing.*;
    import java.sql.*;
    public class Test3 extends JFrame {
        public static void main(String[] args) {
            new Test3();
        public Test3() {
            Container c = getContentPane();
            c.setLayout(new BorderLayout());
            c.setBackground(Color.gray);
            DBConnection db = new DBConnection();
            try {
                Connection conn = DriverManager.getConnection(db.connUrl);
                Statement sql = conn.createStatement();
                ResultSet rs = sql.executeQuery("SELECT * FROM Referrals ORDER BY Referral_Text");
                while (rs.next()) {
                    Item[] items = {
                        new Item(rs.getString(2), rs.getString(2)),};
                JComboBox jcb = new JComboBox(items);
                //Close connections.
                rs.close();
                sql.close();
                conn.close();
            } catch (SQLException e) {
                e.getStackTrace();
            jcb.setPreferredSize(new Dimension(24, 24));
            jcb.setRenderer(new ItemRenderer());
            c.add(jcb, BorderLayout.NORTH);
            setSize(200, 100);
            setLocationRelativeTo(null);
            setDefaultCloseOperation(EXIT_ON_CLOSE);
            setVisible(true);
    // The items to display in the combobox...
        class Item {
            String itemName = "";
            String itemValue = "";
            public Item(String name, String value) {
                itemName = name;
                itemValue = value;
    // The combobox's renderer...
        class ItemRenderer extends JPanel implements ListCellRenderer {
            private JLabel nameLabel = new JLabel(" ");
            private JLabel valueLabel = new JLabel(" ");
            public ItemRenderer() {
                setOpaque(true);
                setLayout(new GridLayout(1, 2));
                add(nameLabel);
                add(valueLabel);
            public Component getListCellRendererComponent(
                    JList list,
                    Object value,
                    int index,
                    boolean isSelected,
                    boolean cellHasFocus) {
                nameLabel.setText(((Item) value).itemName);
                valueLabel.setText(((Item) value).itemValue);
                if (isSelected) {
                    setBackground(Color.black);
                    nameLabel.setForeground(Color.white);
                    valueLabel.setForeground(Color.white);
                } else {
                    setBackground(Color.white);
                    nameLabel.setForeground(Color.black);
                    valueLabel.setForeground(Color.black);
                return this;
    }Thanks!

    He is telling you that there are two problems with your code.
    The first is that you are declaring the items array inside the while loop, which means its scope is too limited - it can't be accessed by the JComboBox which is declared later.
    The second is that you are recreating the items array for every record in your ResultSet. This implies that for every new record, the item(s) already stored will be removed from memory and replaced by the values of the latest record, leading to a single option for your combo box.
    Try instead creating an ArrayList object that you initialise right before the loop, and add items to it's collection as you move along. Then pass that ArrayList to the JComboBox in this way:
              try {
                   Connection conn = DriverManager.getConnection(db.connUrl);
                   Statement sql = conn.createStatement();
                   ResultSet rs = sql
                             .executeQuery("SELECT * FROM Referrals ORDER BY ReferItemText");
                   ArrayList<Item> items = new ArrayList<Item>();
                   while (rs.next()) {
                        items.add(new Item(rs.getString(2), rs.getString(2)));
                   JComboBox jcb = new JComboBox(items.toArray());
                   // Close connections.
                   rs.close();
                   sql.close();
                   conn.close();
              } catch (SQLException e) {
                   e.getStackTrace();
              }

  • How to retrieve string array using Session?

    Hi, I am having some problem retrieving string arrays through session.
    String personalData[] = new String[17];
    personalData = (String [])session.getValue("PersonalData");
    The coding above isn't working. Advise pls.. Thanks

    The getValue() method is deprecated - you should probably be using getAttribute.
    What about this code isn't working? Looks ok to me, as long as the "PersonalData" object in the session is a String[] it should work.
    Cheers,
    evnafets

  • From JTextField into string array

    hello,
    Me and my friend are currently doing a cryptography project for UNI. We are required to read in a word from the JTextField into an array. the problem is the whole word seems to be going into the array as one element. Is there any way to read in each letter in the word into a seperate element of the array??

    Well you can always read the value in the textfield, convert it to a character array and then as you transfer each character to your string array you add a blank string to it, so then it becomes a string.
    Example:
    String sentence = "hello, I am a really loooooooooong string";
    String[] stringArray = new String[sentence.length()];
    char[] charArray = sentence.toCharArray();
    for (int count = 0; count < sentence.length(); count++)
         stringArray[count] = charArray[count] + "";I hope this helps.

  • Loading into String array?

    I made a method that loads 2 strings from a text file, and adds them into an array, but it won't work, heres the code.
    public static void loadFile() {
         for(int i = 0; i < 2; i++) {
              try {
         final Properties testCheck = new Properties();
    final FileInputStream fis = new FileInputStream("myfile.txt");
    testCheck.load(fis);
    fis.close();
    toTest[i] = testCheck.getProperty("test","Nothing Found");
    } catch (IOException ioexception) {
               System.err.println ("Error reading");
    } Thats the method, I make it print out the array, and it shows up Nothing Found, which means it didn't find what the value in the text file? Any help is greatly appreaciated.

    Whatever your problem is, you haven't described it completely.
    Please excuse any typos in the following; my development environment and my internet are on different machines tonight,and I cannot copy-and-paste this over.
    package rc.test;
    import java.io.*;
    import java.util.*;
    public class TestLP
      static String[] toTest = new String[2];
      public static void main (String[] arguments)
      { loadFile();
        for (int i=0; i<toTest.length; i++)
        { System.out.println(toTest);
    public static void loadFile()
    for (int i=0; i<2; i++)
    try
    final Properties testCheck = new Properties();
    final FileInputStream fis = new FileInputStream("myfile.txt");
    testCheck.load(fis);
    fis.close();
    toTest[i] = testCheck.getProperty("test", "Nothing Found");
    catch (IOException ioexception)
    { System.err.println("Error reading");
    With the file "myfile.txt" in the directory in which the program is run, and containing the single line "test TESTING", this program prints:
    TESTING
    TESTING
    All of your code is here, reformatted but otherwise intact; I've added what I surmised to be reasonable drivers to show us whether this code works as expected, and it does.
    Possibilities:
    The array you think you're loading the data into is in a different scope than the one loaded.  You do not give us the declaration of that array, so we cannot tell.
    The printout of the information is somehow flawed.  You don't show us how you output it, so we cannot tell.
    myfile.txt doesn't contain what you expect, or there is more than one copy.  Perhaps "test" is capitalized, which would give the result you indicate.  So would a file that doesn't actually contain "test" as a key.
    Part of the point here is that complete information would cost very little compared to what you've already done, and would allow us to help you better.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • Exporting query result set into CSV file using Forms

    Hi ,
    My requirement is
    -> I need to create a form where I have a Multi line text box and two button.
    -> When I enter a query in text box and click on Execute button, It should execute a select query.
    -> After execution, Result set needs to be exported into an Excel file.
    Please give a hint how to do this????
    Thanks,
    maddy

    as you are using text item to write SQL query by the user
    so for that you need to use the exec_sql package to parse the text items query and get definitions and values of the columns being
    resulted in the result set of the query.
    once your query is execute to the desired connection then you need to use fetch the result to the CSV file by use of the TEXT_io package
    which will open the text file with .csv extension and you have to pass the each line to that text file with comma separated values as "ss","rr" etc.
    or you can use the ole2 package to call the excel application and then fetch the data of exe_sql query to that.

  • How to convert xslt file into string

    i'm writting a java program to use xslt to transform the xml file. i'm encountering the problem when i try to convert the xslt file into string. i've defined my utility class called 'XmlUtil' to carry out the operation of transform xml file through xslt. but in my main java program i need to convert both xml and xslt file into a string in order to input them in my function argument. my function argument is as follows:
    String htmlString = XmlUtil.applyXsltString(xmlContent, xsltString);
    i've already converted xmlcontent into string by using:
    xmlContent = xmlContentBuffer.toString();
    but i don't know how to convert 'xsltString' now ? i've searched the google for an hour but i cannot find the solution. anyone can help ?
    detail of my souce code is as follow:
    import java.io.*;
    import java.net.*;
    import java.lang.*;
    import java.io.StringReader;
    import java.lang.reflect.Array;
    import java.util.Properties;
    import javax.xml.parsers.DocumentBuilder;
    import javax.xml.parsers.DocumentBuilderFactory;
    import javax.xml.transform.TransformerFactory;
    import javax.xml.transform.sax.SAXResult;
    import javax.xml.transform.sax.SAXSource;
    import javax.xml.transform.sax.SAXTransformerFactory;
    import javax.xml.transform.sax.TransformerHandler;
    import javax.xml.transform.stream.StreamSource;
    import org.apache.xml.serializer.OutputPropertiesFactory;
    import org.apache.xml.serializer.Serializer;
    import org.apache.xml.serializer.SerializerFactory;
    import org.w3c.dom.Document;
    import org.w3c.dom.Node;
    import org.w3c.dom.NodeList;
    import org.xml.sax.InputSource;
    import org.xml.sax.XMLReader;
    import org.xml.sax.helpers.XMLReaderFactory;
    import XmlUtil;
    public class FileDownload {
    public static void download(String address, String localFileName){
    OutputStream out = null;
    URLConnection conn = null;
    InputStream in = null;
    StringBuffer xmlContentBuffer = new StringBuffer();
    String temp = new String();
    String xmlContent;
    try {
    URL url = new URL(address);
    out = new BufferedOutputStream(
    new FileOutputStream(localFileName));
    conn = url.openConnection();
    in = conn.getInputStream();
    byte[] buffer = new byte[1024];
    int numRead;
    long numWritten = 0;
    System.out.println (in.toString ());
    while ((numRead = in.read(buffer)) != -1) {
    out.write(buffer, 0, numRead);
    numWritten += numRead;
    temp = new String(buffer);
    xmlContentBuffer.append(temp);
    System.out.println(localFileName + "\t" + numWritten);
    xmlContent = xmlContentBuffer.toString();
    String htmlString = XmlUtil.applyXsltString(xmlContent, xsltString);
    } catch (Exception exception) {
    exception.printStackTrace();
    } finally {
    try {
    if (in != null) {
    in.close();
    if (out != null) {
    out.close();
    } catch (IOException ioe) {
    public static void download(String address) {
    int lastSlashIndex = address.lastIndexOf('/');
    if (lastSlashIndex >= 0 &&
    lastSlashIndex < address.length() - 1) {
    download(address, address.substring(lastSlashIndex + 1));
    } else {
    System.err.println("Could not figure out local file name for " + address);
    public static void main(String[] args) {
    for (int i = 0; i < args.length; i++) {
    download(args);
    }

    I don't understand why you need load the XML and XLS files into a String. A Transformer can be constructed from a Source and there is a StreamSouce which can be constructed from an InputStream. The transform() method can take a Source as input and can produce a Result. There is no need to go near a String representation of either the input.

  • Selecting data to enter into an array

    Hi,
    I am trying to enter data into an array using a case statement to select the values of interest.
    The problem is this, I am running a for loop, and each time it runs it reads a specific value in the existing array (Array 1), using the for loop index as the index for the Array 1. Then I check whether that specific value = a predefined value
    if it does: the case statement writes the index into a new array (Array 2).
    if it does not: the case statement writes a constant - i would like not to have to do this but unfortunately the case loop must have all input terminals connected.
    Essentially I want Array to to consist only of the values of interest, and no default / constant values.
    Any ideas?
    Solved!
    Go to Solution.
    Attachments:
    labviewpic.JPG ‏160 KB

    You are misusing Build Array.  You wire an array into one input and other arrays or values into the others.  See the example I attached.
    Tim Elsey
    LabVIEW 2010, 2012
    Certified LabVIEW Architect
    Attachments:
    BuildArray.vi ‏7 KB
    BuildArray.PNG ‏4 KB

  • How can i use toArray to transfer Set to Array ?

    Dear All,
    Currently, I just can do it by the following code, is there any good idea ?
              Object[] object = set.toArray();
              int[] bb = new int[set.size()];
              for(int i=0; i<object.length; i++) {
                   Object object_aa = object;
                   bb[i] = Integer.parseInt(object_aa.toString());
    Thank you very much

    >      Object[] object = set.toArray();
         int[] bb = new int[set.size()];
         for(int i=0; i<object.length; i++) {
              Object object_aa = object;
              bb[i] = Integer.parseInt(object_aa.toString());
    What type of objects are in your set? Are they String or Integer? You will have to do what you showed--converting each object one by one (or just iterate through the Set using an Iterator instead of using toArray, since you won't need the Object [] when you are done).
    If they are String:
    String[] stringArray = (String []) set.toArray(new String[set.size()]);then you won't need to call toString.
    If they are Integer:
    Integer[] integerArray = (Integer[]) set.toArray(new Integer[set.size()]);Then use integerArray.intValue to fill in
    your int array.
    Or:
    int [] bb = new int[set.size()];
    for (Iterator iter = set.iterator(), i=0;
           iter.hasNext(); i++)
       bb[i] = Integer.parseInt(iter.next().toString());
    }where the middle parseInt and toString can be changed, depending on what type of object your set contains.
    Please use code tags, so that your code gets formatted as above (see buttons above posting box).

  • Set of string into array or a table....

    Hi Experts,
    I am using Oracle 10G, where I need to accomplish a task...
    I am getting a set of string of the sort
    "|session_id~q_id~q_key~rt_id~rt_key~request_type~field_id|session_id~q_id~q_key~rt_id~rt_key~request_type~field_id| ....."
    Here, as you can see every set which has 7 values is delimited by a "| (pipe)" and every value is delimited by a "~" ...
    I need to insert all these into a generic table and before doing that I need to split it into individual values where every set which has 7 values will get into 7 columns in a row...
    Can anyone help me out with a proper logic as to how do i go about accomplishing the same...???

    Hi,
    You have to use regular expression to tokenize string in fragments.
    This is sample for determining CRLF in a string:
    -- Tokenize rows
    FOR token IN ( SELECT REGEXP_REPLACE(REGEXP_SUBSTR(XMLCDATA('custom_string') || Chr(10), '(.*' || Chr(10) || ')', 1, LEVEL ), Chr(10), '') t
    FROM dual
    CONNECT BY REGEXP_INSTR('custom_string'||Chr(10), '(.*'||Chr(10)||')',1, LEVEL ) > 0) LOOP
    token.t --> single fragment
    END LOOP;
    Bear in mind that this forum is for Data Modeler product related issues, feedback etc. So before posting question search for appropriate forum. It's quite possible that you won't get answer while in wrong forum.
    Regards
    Edited by: Dimitar Slavov on Apr 15, 2011 2:11 AM

  • How do I put and sort string data into an array?

    I have a txt file that has the following sample data:
    Sample.txt----
    Jones Bill 12,500 Salesperson
    Adams Frank 34,980 Manager
    Adams John 23,000 Salesperson
    Thompson Joe 59,500 Trainee
    I need to incorporate each line of data into an individual array element, while using a user-defined method
    (ex. setAllValues(String last, String first, String salary, String job)
    How do I loop the data into the array to be displayed and what is the best way to do sorts on this sample data. Any code or clues would be super helpful.
    Sanctos

    If you set up an array of Strings you can use the java.util.Arrays.sort() method to sort it. If you need to sort arbitrary Objects (i.e. your 3 strings as a whole entity) your 3-way object will have to either implement Comparable or you could write a Comparitor class to do the ordering. Not much to it, though.
    Dom.

  • How can I get all the values of a String array profile property using javascript?

    I am trying to build functionality into our site that records all products added to the basket against a user's profile.
    I have so far been able to store the product codes against the profile as a property using Ajax:
           var dataString = ":formid=addProduct&:formstart=/apps/thread/templates/page_product/jcr:content/par/produc t/formstart&:redirect=/content/thread/en/user/cart.html&productId=151515:profile="+profile ;
                         $.ajax({ 
                type: "POST", 
                url: "/content/women/evening/dresses/l-k-bennett-davinadress.html", 
                data: dataString, 
                success: function(data) { 
    In this example I have hardcoded a product ID of 151515.
    In order to save the property as a multi string field you simply replace &productId=151515 with &productId=151515&productId=131313&productId=141414 or as many extra values as you want to build into that string. This stores a productId property against a user profile.
    The issue comes from calling that data back. Using var value = CQ_Analytics.ProfileDataMgr.getProperty("productId") I can get the first value of this array (or the single value if only one is stored).
    However there does not seem to be a way to get any of the other stored values in the array using getProperty. Does anyone know how I can achieve this?

    Hi,
    Don't think that's possible. Even if it were, you wouldn't be able to use/display BOOLEAN type in SQL.
    If you just aim to see what they are, you could do something like this
    select text
      from all_source
    where owner = 'SYS'
       and name = 'DBMS_DB_VERSION'
       and type = 'PACKAGE';Or even
    select dbms_metadata.get_ddl('PACKAGE', 'DBMS_DB_VERSION', 'SYS') from dual;My version is:
    SQL> select * from v$version where rownum = 1;
    BANNER                                                         
    Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
    1 row selectedIn 11g you also have [PL/SCOPE|http://download.oracle.com/docs/cd/E11882_01/appdev.112/e10471/adfns_plscope.htm#ADFNS02203] which might help you even more.
    Regards
    Peter

Maybe you are looking for

  • Rebuild seems to have moved sent attachments to the Trash!

    I just rebuilt my mailboxes in OSX 10.4.3. I happened to look in my trash afterwards, and all these files have magically appeared. They are files that I had attached to outgoing mails. Correspondingly, my Mail Downloads folder is much emptier than it

  • Issues with Safari and Macapp store

    Hi All, I am having following problems on my Mavericks 1) Safari doesn't load anything and same website  can be open on Chrome and other browsers. In safari, gets error like "Safari can't  find sever". This message even comes when try to open iCloud

  • I want to import music from my ipod into itunes, is it possible?

    My old laptop was destroyed, and I lost all of my music with exception of what's on m ipod currently. I got a new computer and installed itunes, but it's not giving me the option to import music into itunes from my ipod. I really want to be able to k

  • Function Module to Create Customer using Account Group

    Hi All, Is there any BAPI Function module that uses the Account Group to create a customer. We are using the FM BAPI_CUSTOMER_CREATEDATA1, but this is not using the Account Group.

  • Re entering sql statements in sql plus

    Hi, How to enter and can edit sql statements in sqlplus without re typing sql statements which were previously executed.