How to typecast a String [] to a List ??

Hi all,
I wanted to typecast a String [] to a List.
The only way I could think of was to run a loop thru the array and add the elements one by one to the List.
Just wondering if there is a smarter way to do it!!
Thanks

Ronakgpatel wrote:
Hi,
Just refer java.util.Arrays class
List lst = Arrays.asList(arr);
Didn't I already say that? Except the spoonfeeding.
db

Similar Messages

  • Reading Hex data- how to typecast from string

    Hi,
    I am reading a file having hex data ( say 100 lines).When i read it i think it is being read as a string.
    How can i typecast or convert it to int .
    I am using dis.readLine() to read from file and assigning it to a variable(int).
    Thanks.
    Edited by: Motorcycle on Jun 10, 2009 3:16 PM

    Sorry for that..:)
    ok a few lines of the file are as folloes
    0x004D1202
    0x0002E1E5
    0x004C1202
    0x0002E1EB
    0x004E1202
    I tried reading it as data [indr][indc].tag = ( int ) dis.readLine() ;
    It said " cannot convert from String to int.
    data is a structure having int variables.
    Thanks.

  • How to error check string for LONG list of strings

    Hi All,
    Let's say I want to compare a string variable with a long list of strings to see if it matches anything in that list. Is there some built-in function that will make this easy. Or should I do it the old fashioned way and load a string array with the list and then for loop through the array comparing each element?
    Cheers,
    ScKaSx

    ScKaSx wrote:
    I'm alittle weak at using interfaces. If the string I am trying to compare is (String grade), then how do I define my List to be ("A+", "A", "A-", "B+", "B", "B-", "C+", "C", .....). This is as far as I've got:
    String grade = 'some letter to be compared'
    String [] GradeList = new String [] {"A+", "A", "A-", "B+", "B", "B-", "C+", "C", .....};Maybe I could summarize what I meant using your example:
    Set<String> PossibleGrades = new HashSet();
    PossibleGrades.add("A+");
    PossibleGrades.add("C");
    String grade = "some letter to be compared";
    if(PossibleGrades.contains(grade) )
       // do something...
    }

  • How to pass query string parameters in list ?

    Hi,
    I have a "Links list" it contains the columns "Empname", "Description" and "Susped/resume" .Here Admin enters the records. When admin enter 'suspend' in "suspend/resume" column it will navigate to "suspend
    page" similarly if enter 'resume' it will navigate to resume page.
    So How I have to set the suspend/resume column by using query string parameter? (dont use hyperlink)
    (We are completely developing my project by using out of box  )
    Appreciate if any one help.
    Thank you.

    Hi,
    It will be easier for others to research on your requirement if you can provide more details about your requirement.
    What is the reason of not using a hyperlink field type? As with hyperlink, we can navigate to other pages easily.
    If you want to use other field type, we will need to write some code(JavaScript) to meet your requirement.
    Best Regards
    Dennis Guo
    TechNet Community Support

  • How to get alternative strings in list of strings.

    Hi experts,
    how to get alternative strings in list of strings.
    eg
    'country1, italy, country2, india, country3, paris, country4, scottland, country5, rome'
    from the above list i need to fetch all the countries and their names separately.
    like country1, country2, country3, country4, country5
    italy, india, paris, scottland, rome
    i am trying the above one in the below fashion
    SELECT SUBSTR
              ('country1, italy, country2, india, country3, paris, country4, scottland, country5, rome',
               1,
                 INSTR
                    ('country1, italy, country2, india, country3, paris, country4, scottland, country5, rome',
                     1,
                     1
               - 1
      FROM DUAL
    can you please any one help me

    If you want the data to be more stuctured, and useful:
    col col_name for a20
    col col_value for a20
    var inlist VARCHAR2(2000)
    exec :inlist := 'country1, italy, country2, india, country3, paris, country4, scottland, country5, rome';
    exec :inlist := replace(:inlist,' ')
    select max(decode(mod(lvl,2),1,value)) col_name
          ,max(decode(mod(lvl,2),0,value)) col_value
    from   (select substr(:InList,start_pos+1, end_pos-start_pos-1) value
                  ,lvl
            from   (select :InList
                          ,case when level = 1 then
                             0
                           else
                             instr(:InList,',',1,level-1)
                           end start_pos
                           ,case when instr(:InList,',',1,level) = 0
                             then length(:InList)+1
                           else
                             instr(:InList,',',1,level)
                           end   end_pos
                         ,level lvl
                    from   dual
                    connect by level <=length(:InList)-length(replace(:InList,','))+1
    group by ceil(lvl/2)
    order by 1;
    COL_NAME             COL_VALUE
    country1             italy
    country2             india
    country3             paris
    country4             scottland
    country5             rome
    Untested on 10g
    Then you could stragg the rows together ...

  • How to typecast the given attribute.

    Hi all,
    I am getting an error.
    I am using dropdownbyindex and using following code.
        Iprivate<ur view name>.IEt_Fragen_output obj = wdcontect.nodeET_Fragen_output.creatEt_Fragen_outputelement();
                   List list1=new ArrayList();
                   for(int i=0;i<obj.length;i++)
                        IPrivateCompView.Idropdownnode data=wdContext.nodedropdown.createdropdownElement();
                        data.setvalue
    ->->->(wdcontext.currentcontextelment.getelementat(i).getfrange);
                        list1.add(data);
                   wdContext.nodedropdown.bind(list1);
    now in this when i try to put (see arrows)currentcontextelment. then i do not get "getelementat(i)." method. Now how to typecast this. I need this method to use "getfrage".
    plz help!!...Its urgent!!!
    Cheers,
    Darshna.

    Hi,
    here is your code. I am using the same structure as you said.
    ValueCollection (value node)
    Values  (value node)
    frage  (value attribute)
         String[] Names = new String []
            "Monthly","Weekly"};
         List monthsOrWeek = new ArrayList();
    IPublic<Component Name>.IValuesElement valuesElement = null;
         for (int i =  0; i < Names.length; i++)
              valuesElement = wdContext.createValuesElement();
              valuesElement.setFrage(Names<i>);  
              monthsOrWeek.add(valuesElement);
         wdContext.nodeValues().bind(monthsOrWeek);
    Hope it helps. Please reward points if it helps....
    Thanks and Regards
    Avijit

  • How to get key name  from parameter list

    hi..
    i want string from parameter list.. i hv already created parameter list like
    ADD_PARAMETER (param_list_id, 'EMPID', TEXT_PARAMETER,'123');
    ADD_PARAMETER (param_list_id, 'EMPNM', TEXT_PARAMETER, 'ABC');
    ADD_PARAMETER (param_list_id, 'EMPADD', TEXT_PARAMETER, 'XXX');
    i got value like '123' ,'ABC', 'XXX' using
    eg. get_parameter_attr(param_list_id,'EMPID',aprmlist,avalue)
    but i want key name like 'EMPID' , 'EMPNM', 'EMPADD' from param_list_id
    is it possible to get this key name from parameter list ???
    Thanks...

    I cannot think of a way to do that. The code that reads the list is supposed to know the key names. That is sort of the point with parameter lists. If you need to have parameter lists that can be interepreted by some code that doesn't know about a specific list but knows how to interpret it by inspecting the key names, perhaps you can specify a separate parameter list with the key names as values and call the keys of that list something generic?

  • How to find a String in a Vector???

    Hi!!
    Thanks in advance for read this post. I have a little problem... please help me.
    I need to find if a String exists or not in a Vector. The vector is a list of results from a database. Here goes my code:
    <html>
    ... html code ...
    <%
    int IdClass = Integer.parseInt(request.getParameter("IdClass"));
    int module = Integer.parseInt(request.getParameter("module");
    Connection conn = null;
    Statement stat = null;
    ResultSet rs = null;
    int oError = -1;
    String oMessage = null;
    List Functions = new Vector();
    CallableStatement cs = null;
    try{
    Class.forName ("sun.jdbc.odbc.JdbcOdbcDriver");
    conn = DBConnection.GetConnection(DBConnection.DSN);
    if (conn != null) {
    cs = conn.prepareCall ("begin procedure(?,?,?,?); end;");
    cs.setInt(1,IdClass);
    cs.registerOutParameter(2,Types.INTEGER);
    cs.registerOutParameter(3,Types.VARCHAR);
    cs.registerOutParameter(4,OracleTypes.CURSOR);
    cs.execute();
    rs = (ResultSet)cs.getObject(4);
    oError = cs.getInt(2);
    oMessage = cs.getString(3);
    if (oError == 0) {
    while (rs.next()) {
    Functions.add(rs.getString(1));
    session.setAttribute("sessionFunctions", Functions);
    out.println("<script>document.location.href=\"Ok.jsp\";</script>");
    else {
    String message = null;
    message = "Error "+oError+": "+oMessage;
    out.println("<script>document.location.href=\"NO.jsp\";</script>");
    cs.close();
    if (conn != null) {
    conn.close();
    %>
    ... html code...
    </html>
    That code generates a Vector that contains this:
    [1, 2, 3, 6, 7, 8, 15, 28, 35, 41, 58, 65, 66, 68, 71, 74]
    In the Ok.jsp page, i have a String like this:
    String access = "2,7,14,15,28";
    First, i need to get the values of the sessionFunctions.
    String X = (String)session.getAttribute("sessionFunctions");
    I need to know if each number (2,7,14...) exists in the vector. For example, in this case, the follow numbers exists: 2, 7, 15, 28.
    So, if the number exists in the Vector, i will generate some HTML code. If not, i will generate a different HTML Code.
    if (String exists in Vector = 1) {
    out.println("Yes!!!");
    else {
    out.println("No...");
    Can somebody help me? I`ve read a lot of examples, a lot of posts in this forum, i`ve look a lot of files of another project in my company, but i can�t find how to do this...
    Thanks in advance.
    Rapeteiro.

    If you are putting a Vector in a session, you should be able to get it back as a Vector. Try this:
    // retrieve Functions Vector from session
    Vector userProfile = (Vector) session.getAttribute("sessionFunctions");
    String access = "2,7,14,15,28";
    // prepare a Vector from this string
    Vector accessVector = new Vector();
    StringTokenizer acsTokenizer = new StringTokenizer(access, ",");
    while(acsTokenizer.hasMoreTokens ())
    accessVector.addElement (acsTokenizer.nextElement ());
    // check for each function in string against userProfile Vector
    for(int f=0;f<accessVector.size ();f++)
    String function = (String)accessVector.elementAt (f);
    if(userProfile.contains (function)
    %>User has access to this function<%
    else
    %>User does not have access to this function<%
    Hope this helps!
    -Mak

  • How to parse a string containing xml data

    Hi,
    Is it possible to parse a string containing xml data into a array list?
    my string contains xml data as <blood_group>
         <choice id ='1' value='A +ve'/>
         <choice id ='2' value='B +ve'/>
             <choice id ='3' value='O +ve'/>
    </blood_group>how can i get "value" into array list?

    There are lot of Java XML parsing API's available, e.g. JAXP, DOM4J, JXPath, etc.
    Of course you can also write it yourself. Look which methods the String API offers you, e.g. substring and *indexOf.                                                                                                                                                                                                                                                                                                                                                                                                               

  • How do I get the reminders, in list view, to display in date order?

    How do I get the reminders, in list view, to display in date order? I can't seem to get them to display in date order on either my ipad or iphone.
    Yes i know I can look at date view, but i don't like that view. I excepted the list view to display all reminders in date order.
    Thanks!

    You need to create a stringwriter, wrap it in a printwriter, then print to the printwriter, then convert the stringwriter to a string.
    Here's an example:
    StringWriter sw = new java.io.StringWriter();
    PrintWriter pw = new java.io.PrintWriter(sw);
    e.printStackTrace(pw);
    String strError = sw.toString();
    I hope this works. I didn't test the above code. I don't think I'm leaving anything out, but it's been a while since I've done it. Either way, it should get you on the right track to get what you need.
    Hope that helps.
    Michael

  • How to typecast Object Class object dynamically

    Hai every one
    i have a object of any particular class , but i don't know the variables in that class object. But i have string variable contains value of variables in that class object.
    So i use following method for get value of variables in that class object.
    class ObjectCLass
         Sub s=new Sub();
         public static void main(String[] args)
              ObjectCLass a=new ObjectCLass();
              try
                   System.out.println(*a.getClass().getDeclaredField("s").get(a)*);
              catch(Exception e)
                   System.out.println("Exception");
    class Sub
         int i=5;
         public void print()
              System.out.println("Hello World!");
    }Here the bolder line give Object class object. By using this Object class object i need access the variable i and method print(). So i need to cast Object class object into sub class
    so how can i typecast it
    i try with following methods , but i cant succeed
    1.(  *(a.getClass().getDeclaredField("s").get(a).getClass)*   a.getClass().getDeclaredField("s").get(a)   ).print() ;
    2.(  (Class.forName(�Sub�) ) a.getClass().getDeclaredField("s").get(a) ).print();Please any one one help me how to typecast it dynamically
    By
    Thiagu

    If you know you're going to invoke the "print" method on an object, then you also need to know the type of the class, or interface, which has that method.
    It seems what you are looking for is a tutorial on interfaces.
    http://java.sun.com/docs/books/tutorial/java/IandI/index.html
    In a nutshell, you can set up an interface which defines a "print" method, and create class(es) which implement that interface. Then as long as you have an object which implements that interface, but do not know the exact type of that object, you can simply cast it to the interface type and invoke the method.

  • How to compare two strings whether both are equal while ignoring the difference in special characters (example: & vs & and many others)?

    I attempted to compare two strings whether they are equal or not. They should return true if both are equal.
    One string is based on Taxonomy's Term (i.e. Term.Name) whereas other string is based on String object.
    The problem is that both strings which seem equal return false instead of true. Both string values have different special characters though their special characters are & and &
    Snapshot of different design & same symbols:
    Is it due to different culture or language?
    How to compare two strings whether both are equal while ignoring the difference in special characters (& vs &)?

    Hi Jerioon,
    If you have a list of possible ambiguous characters the job is going to be easy and if (& vs &) are the only charracters in concern awesome.
    You can use the below solution.
    Before comparing pass the variables through a replace function to standarize the char set.
    $Var = Replace($Var,"&","&")
    This is going to make sure you don't end up with ambiguous characters failing the comparison and all the char are "&" in this case.
    Similar technique is used to ignore Character Cases 'a' vs. 'A'
    Regards,
    Satyajit
    Please “Vote As Helpful”
    if you find my contribution useful or “Mark As Answer” if it does answer your question. That will encourage me - and others - to take time out to help you.

  • How to determine if string contains HashSet item using LINQ

    Hi,
    I know how to iterate through a HashSet to see if an item is contained in a string.  But, I can't quite figure out how to do it with LINQ.
    Something like if( string.Contains(???))
    I would appreciate any help!
    Thanks much!!

    Thanks everyone.  I like the examples posted above.
    Actually, what I want to know is if any HashSet values can be found in a string using LINQ
    HashSet<string> terminals = new HashSet<string>();
    terminals.Add("FD4A");
    terminals.Add("FD4B");
    terminals.Add("FD4C");
    //a collection of a bunch of transactions done at various terminals
    List<string> transactionList = new List<string>();
    foreach (string transaction in transactionList)
        foreach (string terminal in terminals)
           if (transaction.Contains(terminal) == true)
                //this is one of the transactions I want - do something
                break;
    Thanks much and have a great weekend!!

  • How to get actual value from LOV list

    Like Subject says: How to get actual value from LOV list. Any help will be appreciated.
    Thanks.

    Thanks Shay, I did it with bind variable because I'm not using JSF. Is there any chance to post solution using standard JSTL or HTML expression. I have something like this: LOV displays some Companies names:
    <html:select property="UserJobCompanyId"
                             disabled="${!bindings[\'UserJobCompanyId\'].updateable}"
                             onchange="submitform();">
                  <html:optionsCollection label="prompt" value="index" property="UserJobCompanyId.displayData"/>                                                     
                </html:select>and I want to get CompanyID of selected Company.
    Thanks, again.

  • How to remove available downloads from the list

    how to remove available downloads from the list without it resuming when i open itunes or check for available downloads?

    There is not a way to remove them from the list.  Just let them download, and then delete them from your library when they are done.

Maybe you are looking for