Switch with a string?

Is it possible to do a switch with a String?
The following does not seem to work
String a = "bubble";
switch(a) {
  case "tricks":
    System.out.println("This trick doesn't seem to work");
    break;
  case "bubble":
    System.out.println("It's gone and burst my bubble");
    break;
}Any ideas?
Thanks
Bubble

Brannor:
E.g. switch (testString.hashCode()) {
case ("case 1".hashCode())...This won't work. You need a constant expressions for the cases, a method like hashCode() won't work there.
Yogee:
1. Different Strings are not guaranteed to generate different hashcodes.True, but its such a unlikely event that the strings' hashcodes will be equal that someone would still be able to do this reasonably in some situations. but I wouldn't do this in my code
2. The algorithm used to generate the hashcode is not guaranteed to be the same on different platforms.There is a String hashcode formula, and its not ambiguous. The method is implemented entirely in java and so it will be the same on different platforms. Object.hashCode() though can be different on different platforms.
3. The algorithm used to generate the hashcode is not guaranteed to be the same on different
java versions.We can use that argument against writing anything in the API though, since the language can always change. Has Sun ever indicated that they might want to change the API specs for Strings's hashCode?

Similar Messages

  • Switch with string

    hi, i've been reading a few of the previous discussions on usability of switch with string. why can't switch be made to work with all datatypes? is it really such a big deal? if there is a serious reason for not letting switch work with all datatypes pls bring it to the open. i'm an avid java guy and hope that there's the least amount of ambiguity with this beautiful language.
    sunny

    switch only works for primitive numersic types.
    I am not positive about the reason for this.
    One guess is that for switch to work with Objects it would have to automatically evaluate using the equals() method. In general the Java language doesn't allow constructs that aren't explicit. This is the kind of thing the throw into C#.
    It would be nice if you could do a switch of the references. That way you could use switch with typesafe enumerations.

  • Switching between 2 string values

    This is probably a trivial question, but how do I switch between 2 string values to be sent to one input terminal of a larger concatonated string function. The values need to be changed every 100ms or so.
    Thanks
    mhaque
    Solved!
    Go to Solution.

    Why so complicated???
    You can do this particular string manipulation in a single atomic operation using "Append True/False String"
    LabVIEW Champion . Do more with less code and in less time .
    Attachments:
    AppendTF.png ‏3 KB

  • Building a table with a string data type

    I am using the Build Table function and I would like to be able to label my columns on the first iteration with a string data type, which doesn't seem to be an acceptable signal for the Build Table function. However, the express table is located under "text indicators" on the front panel, so it seems like there should be a way to do this..

    Ah, the "Build Table" Express VI. I hate Express VIs.
    That Express VI is nothing more than a really complicated way of creating a 2D array of strings. The Express VI has no inputs for the row and column headers, so you need to add them in yourself. The same would be true for a regular table control/indicator. Here's what you need to do:
    Right-click on the table indicator and select Visible Items -> Column Headers.
    Right-click on the table indicator and select Create -> Property Node -> Column Header Strings[]. LabVIEW will attach a property node to the cursor and switch to the block diagram. Plop down the property node on the block diagram.
    Right-click on the property node on the block diagram and select "Change All to Write".
    Right-click on the property node and select "Create -> Constant". This will give you an array of strings, and you can enter the column headers in each array element.
    Wire the array to the property node.
    Connect the property node to the Build Table Express VI using the error clusters.
    Message Edited by smercurio_fc on 07-02-2008 09:25 AM
    Attachments:
    Example_VI_BD6.png ‏3 KB

  • Unmanaged switch with CDP?

    I am trying to find an unmanaged cisco switch that has cdp.  Technically the switch doesn't have to be unmanaged, but I am looking for a cheep switch with only 5-10 ports that also has cdp.  I can't be sure if the small cisco SD series switches, formerly s***sys, have cdp now or not.

    Brannor:
    E.g. switch (testString.hashCode()) {
    case ("case 1".hashCode())...This won't work. You need a constant expressions for the cases, a method like hashCode() won't work there.
    Yogee:
    1. Different Strings are not guaranteed to generate different hashcodes.True, but its such a unlikely event that the strings' hashcodes will be equal that someone would still be able to do this reasonably in some situations. but I wouldn't do this in my code
    2. The algorithm used to generate the hashcode is not guaranteed to be the same on different platforms.There is a String hashcode formula, and its not ambiguous. The method is implemented entirely in java and so it will be the same on different platforms. Object.hashCode() though can be different on different platforms.
    3. The algorithm used to generate the hashcode is not guaranteed to be the same on different
    java versions.We can use that argument against writing anything in the API though, since the language can always change. Has Sun ever indicated that they might want to change the API specs for Strings's hashCode?

  • SharePoint 2013 List View with query string filter stops working after editing view from browser

    I have created one list definition in which I have added one list view which will filter data from query string paramater
    So when I am creating list from my list definition, view with query string filter is working fine.
    But when I am modifying view from UI(I am not changing any thing , just opening "Modify View" page and then click on "Save" button), view gets stop working means it's not filtering data based on query string
    Any suggestion what I am missing?
    Below is my list view schema
    <View BaseViewID="11" Type="HTML" TabularView="FALSE" WebPartZoneID="Main" DisplayName="$Resources:OIPLBScoreCard,viewFilterTasksByTarget;" MobileView="True" MobileDefaultView="False" Url="FilteredTasks.aspx" SetupPath="pages\viewpage.aspx" DefaultView="FALSE" ImageUrl="/_layouts/15/images/issuelst.png?rev=23">
    <Toolbar Type="Standard" />
    <ParameterBindings>
    <ParameterBinding Name="NoAnnouncements" Location="Resource(wss,noXinviewofY_LIST)" />
    <ParameterBinding Name="NoAnnouncementsHowTo" Location="Resource(wss,noXinviewofY_DEFAULT)" />
    <ParameterBinding Name="TargetId" Location="QueryString(TargetId)" />
    </ParameterBindings>
    <JSLink>hierarchytaskslist.js</JSLink>
    <XslLink Default="TRUE">main.xsl</XslLink>
    <JSLink>clienttemplates.js</JSLink>
    <RowLimit Paged="TRUE">100</RowLimit>
    <ViewFields>
    <FieldRef Name="Body"></FieldRef>
    <FieldRef Name="Title"></FieldRef>
    <FieldRef Name="StartDate"></FieldRef>
    <FieldRef Name="DueDate"></FieldRef>
    </ViewFields>
    <ViewData>
    <FieldRef Name="PercentComplete" Type="StrikeThroughPercentComplete"></FieldRef>
    <FieldRef Name="DueDate" Type="TimelineDueDate"></FieldRef>
    </ViewData>
    <Query>
    <Where>
    <Eq>
    <FieldRef Name="oipscTargetLookup" LookupId="TRUE"/>
    <Value Type="Lookup">{TargetId}</Value>
    </Eq>
    </Where>
    </Query>
    </View>
    I have one lookup field from "Target List" in my source list and I want to filter data based on that lookup field.

    Hi JayJT,
    The Miscellaneous is located in the contact list that you used for the connection.
    So , you need to edit the page, then edit the contact list that you used, in the web part properties of the contact list, you will find Miscellaneous, then expand it and select ‘Server Render’ .
    I hope this helps.
    Thanks,
    Wendy
    Wendy Li
    TechNet Community Support

  • Using Catalyst 3550 Switch with Linksys Home Router and Cable Internet

    I've about pulled what little hair I have out of my head on this one, and need some configuration help.
    I have a Cisco Catalyst 3550 switch with five Windows 7 desktops, an Avaya PBX and five Avaya IP phones attached.  All of these devices are on a 192.168.0.0/24 subnet, and are communicating properly.  I will refer to this as network # 1. I also have SEPARATE network, we'll call network # 2, using AT&T ADSL service and a Netgear 4-port/wireless router/ADSL modem combo device, which is functioning properly with a couple of other Windows 7 desktops over its own wired Ethernet network, using DHCP, and also on a 192.168.0.0/24 subnet.  I thought it would be a simple integration, just plugging one of the 3550's ports to one of the DSL router's ports, in order to give the five Windows 7 desktop computers on network # 1 internet access via the DSL modem. Guess I was wrong.  When I connect the two switches together, although I get a good connectivity (green lights on both ports) and am able to ping the DSL router's gateway address (192.168.0.252) from network # 1's computers, the computers on network # 1 cannot access the internet. Also, the working computers on network # 2 lose their internet access as long as the two switches are connected together. I am not a Cisco guru, but there's got to be a way to make this scenario work.  Can someone provide me with a 3550 configuration that will allow me to extend my internet service from network # 2 on the DSL router to my 3550 switch and their computers?  Here's what I am looking for:
    INTERNET ---> ADSL MODEM ---> NETGEAR ROUTER ---> CISCO 3550 SWITCH ---> NETWORK DEVICES WITH INTERNET ACCESS

    The Netgear router is probably what's doing the natting. Is the 3550 configured for routing or is it straight L2? If you have the 3550 configured as L3, then it's going to be easy to do what you want. Just add a static route on the Netgear to point the subnet that it doesn't know about to the 3550. For example, if the Netgear is addressed at 192.168.1.1 and the Cisco 3550 is addressed at 192.168.1.2, but it also knows about the 192.168.0.0/24 (separate vlan), then you would put a static route on your Netgear for 192.168.0.0/24 to go to 192.168.1.2.
    The way that I would do it is to create a separate vlan on the 3550 and assign an address to it. Once you do that, make the port that the other switch connects to an access port of that vlan. (It would need to be on the same subnet as the existing equipment.) All of your devices would use it as a default gateway and then you would do the rest as above. You could also use RIP between the Netgear and Cisco if you can't do static routing.
    HTH,
    John

  • After installing an update I am no longer able to hear sound out of my speakers. A red light comes on where the headphone jack is. I have already attempted to trip to switch with a wooden toothpick in the headphone jack but have not had luck.

    after installing an update I am no longer able to hear sound out of my speakers. A red light comes on where the headphone jack is. I have already attempted to trip to switch with a wooden toothpick in the headphone jack but have not had luck.

    Have you gone into system prefs nad made sure that the headphone port is set to audio out. And not audio in.
    Also make sure that you are selecting built in speakers for your audio output.
    If that does not fix it try doing a Pram reset.
    Shut your mac down.
    Press the startup button.
    Hold down the following keys. Command Option P and R. Wait till you hear the chime 2 times. Then let go. See if that fixes it.

  • Sling mapping issue with Query String

    For a button component, URL behaves differently with query string. Please let me know the sling mapping example for query string.
    Button component behavior across env:-
    Working Scenario:-
    - In Author edit mode, URL pointing to "/content/<websitelink>"
    - In Author preview mode shows URL "<host>:<port>/content/<websitelink>.html"
    - In Publisher mode shows URL, "<host>:<port>/<websitelink>", we do not want "/content" before website link so it is fine.
    Failure Scenario with query string:-
    - In Author edit mode URL pointing to "/content/<websitelink>?username=han"
    - In Author preview mode with URL "<host>:<port>/content/<websitelink>?username=han"
    - In Publisher mode, <host>:<port>/content/<websitelink>?username=han - Here we see the content, which is not acceptable in our scenario.
    Please let me know the mapping changes when we have a URL with query string.

    1) I assume you configure as per the rules mentioned in http://sling.apache.org/site/mappings-for-resource-resolution.html --> 'Mapping Entry Specification' under /etc/map. Based on the configuration in /etc/map and the website that we publish, it translates and shows all the applicable combination in the Felix console http://<host>:<port>/system/console/jcrresolver.
    2) How does Adobe CQ 5.4 resolve the right mapping, if we have multiple map folder like below in /etc directory with the same website with different rules.
    etc/map --> http --> <website> with property sling:match, sling:internalRedirect
    etc/map.publish --> http --> <website> with property sling:match, sling:internalRedirect
    etc/map.publish-stag --> http --> <website> with property sling:match, sling:internalRedirect
    Kindly clarify.

  • Toggle switches with if else

    I am trying to toggle various switches based off of others and am wondering how I can go about this. For example, if switch A is on, B should toggle off. If I toggle B on, A should toggle off. Any help in doing this would be appreciated. Thanks.

    Thank you for an easy question..... 
    There's a mode in the Switch options that allows you to create a single switch with two channels, where only one will be on.
    - cj
    Measurement Computing (MCC) has free technical support. Visit www.mccdaq.com and click on the "Support" tab for all support options, including DASYLab.

  • How to replace a particular striing with another string in jtextpane

    how to get replace a particular string with another string of a jtextpane without taking the text in a variable using getText() method .

    Thanks for your answer,
    "relevant object" means for you datasources, transfer rules and transformations ?
    With the grouping option "Save for system copy" I can't take easily all datasources, and others objects
    Will I have to pick all object one by one ?
    What would be the adjustement in table RSLOGSYSMAP ? For the moment it's empty.
    Regards
    Guillaume P.

  • Problem with output string to command

    hey i have no idea why this aint working
    its a simple output string to command.
    what it is supposed to do is make a new directory given by the input string
    e.g. mkdir /home/luke/dep
    thanks for the help
    //methods input save files
         saveFile = JOptionPane.showInputDialog("Save Files To : ");
         //method command for saving files
         //Stream to write file
         FileOutputStream fout;          
         try { Process myProcess = Runtime.getRuntime().exec("mkdir" + saveFile );
          InputStreamReader myIStreamReader = new InputStreamReader(myProcess.getInputStream());
          fout = new FileOutputStream ("file.txt");
          while ((ch = myIStreamReader.read()) != -1) { new PrintStream(fout).print((char)ch); } }
              catch (IOException anIOException) { System.out.println(anIOException); }

    What you fail to understand is that "aint working" and "Problem with output string to command" tells us absolutely squat about what your problem is. This is the same as saying to the doctor "I'm sick" and expecting him to cure you. As mentioned by Enceph you need to provide details. Do you get error messages? If so post the entire error and indicate the line of code it occurs on. Do you get incorrect output? Then post what output you get, what output you expect. The more effort you put into your question the more effort others will put in their replies. So until you can manage to execute a little common sense then the only responses you will get will be flames. Now is your tiny little brain able to comprehend that?

  • Comparing string delimited by semicolon in a column with another string

    Hi
    I have requirement like comparing a column which contains the string delimited by semi colon with a string delimited by semicolon. i.e. comparing the multiple values with multiple values.for this purpose i am using the following code
    select ams.application_id,it_mgmt_chain
    FROM tb_ams038_application ams,THE
    (SELECT CAST
    (Appmgmt_Str_To_Table
    (NVL (ams.it_mgmt_chain,
    ) AS appmgmt_tabletype_string
    FROM DUAL
    AND (COLUMN_VALUE IN ( SELECT COLUMN_VALUE
    FROM THE
    (SELECT CAST
    (Appmgmt_Str_To_Table
    (nvl(NVL (replace('1234;8383;83939;93939',',',';'),
    ams.it_mgmt_chain
    ) AS appmgmt_tabletype_string
    FROM DUAL
    here in the above it_mgmt_chain has the string containing numbers seperated by semi colon. and the Appmgmt_Str_To_Table function used to split the string and return it in the form of list. and appmgmt_tabletype_string is a varray which is created for spliting and storing purpose.
    Can anyone please suggest the best way to do this task as the above code is giving a performance issue.

    This example uses a "|" not a semicolon but it leverages the REGEXP_SUBSTR, SUBSTR, LENGTH to perform a parsing action.
    http://blog.mclaughlinsoftware.com/plsql-programming/a-result-cache-function-returning-a-collection/
    You may wish to remove the "THE" and replace it with "TABLE" too. Good luck.

  • File uri with query string can't be propagated by desktop.browse()

    I have been trying to show some help pages using the following command:
    java.awt.Desktop.getDesktop().browse( helpURI);
    while the helpURI.toString() prints out the following:
    file:///C:/Share/Code/phoenix/Install/REDIST/Help_Files/en/wwhelp/wwhimpl/js/html/wwhelp.htm?context=BD&href=Chapter%202%20-%20Configuration.1.14.html
    But when the getDesktop().browse() API is executed it will only propagate the uri-path and not the query string.
    So the browser shows the following url as a result of the browse() call:
    C:\Share\Code\phoenix\Install\REDIST\Help_Files\en\wwhelp\wwhimpl\js\html\wwhelp.htm
    But if I manually copy the string "file:///C:/Share/Code/phoenix/Install/REDIST/Help_Files/en/wwhelp/wwhimpl/js/html/wwhelp.htm?context=BD&href=Chapter%202%20-%20Configuration.1.14.html" to the internet explorer it works fine.
    So can somebody give me any guidance on how I can propagate the file uri with query string through the browse() API or is there a better API for that?
    Sibon.

    The "cmd /S /C" suggestion didn't seem to work. I don't think the problem is in java but how the command line parameter needs to be added from msdos shell to "iexplore.exe"
    When from the command line I enter the following command:
    iexplore.exe file:///C:/Share/Code/phoenix/Install/REDIST/Help_Files/en/wwhelp/wwhimpl/js/html/wwhelp.htm?context=BD&href=Chapter%202%20-%20Configuration.1.14.html
    I get the same result as invoking from java Desktop API --- it truncates everything from question mark. I tried palying around with double quotes, single quotes, escaping and nothing seem to work.
    Any ideas?

  • SelectMany checkbox value-binded with HashMap String,ArrayList

    Hello,
    Someone can help me please?
    Im trying to create a page with a lot of HtmlSelectManyCheckbox, and i need to value-bind then to the same Object in my BackingBean.
    First i attemped to bind all HtmlSelectManyCheckbox with a single ArrayList, but only the last SelectMany had their values inserted on the ArrayList...
    So, now im trying to bind all the HtmlSelectManyCheckbox with a HashMap<String,ArrayList>, because i would have just one object and for each entry I would have the checkboxes that were cheked in a single HtmlSelectManyCheckbox.
    Now my question: there is a way to make this work?
    my code example
    Backing bean
    private HashMap<String, ArrayList> respostaMatrizCheck = new HashMap<String, ArrayList>();
         public HashMap<String, ArrayList> getRespostaMatrizCheck() {
              return respostaMatrizCheck;
         public void setRespostaMatrizCheck(HashMap<String, ArrayList> respostaMatrizCheck) {
              this.respostaMatrizCheck = respostaMatrizCheck;and the bindings
    <h:selectManyCheckbox value="#{backingBean.respostaMatrizCheck['1'] }">
    <h:selectManyCheckbox value="#{backingBean.respostaMatrizCheck['2'] }">And the error message given when i tryed this is the following:
    javax.servlet.ServletException: ValueBinding for UISelectMany must be of type List or Array
    Any help would be welcome.
    Thanks,
    Ferry

    Has anybody solved a problem like this? I am facing the same problem and no response helped me so far.
    Here is the web code:
    <h:selectManyCheckbox value="#{processor.languages.languages1}">
         <f:converter converterId="languageConverter" />
         <f:selectItems value="#{categoryController.allLanguagesAsSelectItems}" />
    </h:selectManyCheckbox>My backing bean "processor" looks like this:
         public Map<String, List<MyObject>> getLanguages() {
              return languagesMap;
         }(The backing bean has no "setLanguages()-method" since I did not need any with Map<String, String> for example.)
    The converter I use creates a "MyObject" instance in its "getAsObject" conversion method.
    I think everything should be okay then but the exception I get after submitting the page is:
    java.lang.IllegalArgumentException: ValueBinding for UISelectMany must be of type List or Array
         org.apache.myfaces.shared_impl.renderkit._SharedRendererUtils.getConvertedUISelectManyValue(_SharedRendererUtils.java:191)
         org.apache.myfaces.shared_impl.renderkit.RendererUtils.getConvertedUISelectManyValue(RendererUtils.java:630)
         org.apache.myfaces.shared_impl.renderkit.html.HtmlCheckboxRendererBase.getConvertedValue(HtmlCheckboxRendererBase.java:308)
         javax.faces.component.UISelectMany.getConvertedValue(UISelectMany.java:308)
         javax.faces.component.UIInput.validate(UIInput.java:350)
    .....Edited by: rapthor on Oct 31, 2007 6:39 AM

Maybe you are looking for

  • EDI Invoice before Goods receipt

    Hello , Purchase orders are created in the system with GR based IV checked and the purchase orders are sent by EDI to the vendor . The vendor ships the material and also send the EDI invoice . Since GR is not posted in the system by that time , EDI i

  • Unable to launch Litetouch.vbs (LiteTouch.wsf) from UNC path - A connection to the Deploayment Share Could not be made

    I am having a difficult time figuring out this issue. Here is the back story. The particular deployment share is not used in the traditional sense of deploying OS images. Instead, it is only used in deploying applications. I actually have three share

  • Streaks in iPhone 6 plus screen

    There are two iridescent streaks across the screen of my iPhone 6 plus. I just got it today and Have done nothing other than set it up. What is the fix, please?

  • Problem with app installed by other user

    I have an iphone 4 with IOS 7.1.2 Serial number 6Q03595HA4S My cell phone was given to me by my wife, and she installed some apps with her apple ID (whatsapp's is the mos important to me), since i installed new apps with my apple ID. each time  i doe

  • Installing medium-cost RAM on my Mac Pro

    Hi everybody! I've just bought a 2x 2.66GHz Mac Pro and it's wonderful. However, I ordered it with a minimum configuration because I thought I could find expansion pieces on the market. Is there any problem if I install a 1GB-667-DDR2 RAM module non-