Chain of Split which begins with a delimiter

Hi all
I am trying to split a string using "-" as a separator and store values (strings) in a list. The problem is that, because the string begins with the delimiter, I get an empty (as my first item) element in my list. I would appreciate your help to solve this problem.

My code is:
public class SplitString { 
   public static void main(String[] args) {
     String str = "-Djava.security.policy=$ORACLE_HOME/j2ee/home/config/java2.policy" +
                  "-Djava.awt.headless=true -Dhttp.webdir.enable=false";
          
          SplitAndStoreAsList(str);
     }
     
    public static void SplitAndStoreAsList(String str){
     List<String> list = Arrays.asList(str.split("-"));
          
     for (int i = 0; i<list.size(); i++){
             System.out.println(i + ": " + "-" + list.get(i));
     }
          
    }
}
The output should be
0: -Djava.security.policy=$ORACLE_HOME/j2ee/home/config/java2.policy
1: -Djava.awt.headless=true 
2: -Dhttp.webdir.enable=false
But it is
0: -
1: -Djava.security.policy=$ORACLE_HOME/j2ee/home/config/java2.policy
2: -Djava.awt.headless=true 
3: -Dhttp.webdir.enable=false

Why not just change the regular expression that is

     List list = Arrays.asList(str.split("(?

Tags: Java

Similar Questions

  • which begins to turn my abilities wireless off in my lenovo SL510 laptop with win7 pro

    Which begins to turn my abilities wireless off in my Lenovo SL510 laptop with Win7 pro? I have a dlink router connected to my office. My system works fine until I leave for a short period, then it disconnects?

    Thanks for any help!

    Hello


    Modifications were made to the software or the hardware of the computer before the show?
     
    Method 1:
    Check out the link and follow the troubleshooting steps and check.
     
    Method 2:
    Visit the link provided and follow the steps.
     
    Method 3:
    Reinstall the drivers for the network adapter and check if it helps.
  • Split a string using regexp_substr with consecutive delimiter

    I split a string with tubes as a delimiter. A string like this for example:

    "THIS |" EAST | ONE | EXAMPLE '

    If I do something like this:

    SELECT REGEXP_SUBSTR('THIS|IS|AN|EXAMPLE', '[^|]+', 1, 4) FROM DUAL
    

    I would get the word EXAMPLE

    But if the string is like this:

    "THIS |" EAST | ONE | EXAMPLE '

    With the above query, I always get EXAMPLE, but the word should be in the next position (5) because after IS, there should be an empty element

    Is it possible to change the regular expression to also get the empty element?

    Thanks in advance

    Well, the way I understand it, you get this behavior, because there is 'nothing' between the delimiters. so there is a field, so it does not display it don't think the regular expression.

    Try it with a space between the delimiters - works fine.

    So, with this in mind, the simplest solution might be something like that?

    regexp_substr (replace(c,'||','| |'), "[^ |]") +' 1, 4)

    [edited to avoid having a partial answer marked "correct"]

    As mentioned below by a few others, there are other solutions using regular expressions.

    The solution above does not work if more than 2 consecutive fields are empty, or if the first or last is empty.

    A simple tweak to the logic would help with this:

    RTrim (regexp_substr (replace (c,'|))) ',' |'), ' [^ |] +', 1, level))

    However, even if it has still some limitations compared to the solution of the full regular expression mentioned by Frank, below.

    [/ Edit]

  • File does not begin with '% PDF -'. Error opening PDF files in the browser

    When the user rent a report via internet explorer, it shows "file does not begin with '% PDF -'". I reinstalled acrobat, but it still does not.

    Pdf_Error.JPG

    Configuration as follows

    Adobe Acrobat Reader X

    Name of the operating system: Microsoft Windows 10

    Browser: Internet Explorer Version: 11.00.10586

    The file you are trying to open is not a (valid) PDF file. Contact the Web site from which you guessed it, and report the problem to them.

  • vCenter Orchestrator - list all VM that begin with "S".


    Hello

    I would list all my VM that begin with "S" in vCenter Orchestrator but, I can't find any script to do this.

    Maybe someone already do this.

    I would do this:

    Lists all the vm.name start with "S"

    But I do not know the syntax of script!

    After, I have the list, I would delete all the vm which differ from Vmname-current date.

    Thank you in advance

    Good day

    Chris

    Hello

    I found how to list all the VM that begin with "S", here's the script:

    VM. Name.Substring (0.1) == "S".

    Good day

    Best regards

  • IsDefined dislikes the names of variables beginning with a number. Unless they are defined...

    Hello

    I detected a strange (for me) behavior of the IsDefined function. I have something like:

    < cfif IsDefined ("url.vose") > < cfset = "value" unevariable > < / cfif >

    < cfif IsDefined ("url.3d") > < cfset = "value" unevariable > < / cfif >

    * If url.3d is set, all right. All work as expected.

    * If url.3d is not defined, CF throws an error "Parameter 1 of function IsDefined, which is now url.3d, must be a syntactically valid variable name".

    * If I use structKeyExists (url, "3d") instead of IsDefined("url,3d"), works as expected.

    I have tried different combinations of variable names and extended (EP, url.5d, or form.3d) and the problem seems to be the number at the beginning of the name of the variable.

    This is the expected behavior? I found it very strange that it works if the variable exists and only generates an error if not. Can it be considered a bug and should be reported?

    TIA,

    It doesn't matter if the language is CF or JavaScript or PHP-HTML - variable names are considered invalid if they do not begin with a letter or underscore.  You must friezer prefix a variable name with a number.

    Also, I have heard many developers complain IsDefined().  Use rather StructKeyExists().

     blah blah blah 
    
     blah blah blah 
    

    V/r,

    ^_^

  • Writing a query to display data WHERE the data in column do not begin with 'Rep '.

    Hello

    * (Assuming file_name is a column of table $file_log) *.

    Please tell me

    How to write a query where I want to display the data for which File_Name does not begin with name like Reports_

    Please tell me.

    Thank you

    Hello

    I hope that this might help

    SELECT * FROM FILE_LOG_TABLE WHERE FILE_NAME NOT LIKE 'Reports_%';
    

    see you soon

    VT

  • Ask the glossary of words beginning with a specific letter

    I have a page which is a glossary of terms. This is a table of 2 field.  Word and definition.  Is there a way to pull all the words beginning with a specific letter?  How complicated this request would be?

    Select * from mytable where the word like 'a % '.

  • How can I remove an email address which clashes with another that is a little different

    I have an e-mail address that constantly appears when I try to send an e-mail to my wife, like e-mail address begins with the same first name as my wife and if I'm not careful I could easily send the email to the wrong person.

    is it possible to delete this address.

    Delete the contact from Contacts.

    If it is not a contact, then search in Mail, former winners (Windows menu) and it remove it.

  • I changed the my imac with a new drive and I lost the original CD/DVD which came with the new Mac.

    I changed the my imac with a new drive and I lost the original CD/DVD which came with the new Mac.

    and when I go to install the mac lion antiracism apple with reticle logo means error

    what can I do with these

    Please help money

    You can get the replacement system install & Restore CD/DVD of the customer support of Apple - to the United States, (800) 767-2775-for a sum low S & h. you will need to have the model or the serial number of your Mac available.

    If you are not in the United States, you may need to go through the regional Apple Store that serves your location to find the phone number. Here is a list of links to all - http://store.apple.com/Catalog/US/Images/intlstoreroutingpage.html , another resource: International Support Phone #s.

  • Mail crashes when the address begins with 'j '.

    Hello

    When I opened a new mailwindow in AppleMail and start typing that address whitch starts with the letter j, the program crashes.

    Any other letter works very well.

    It is possibel to trigger the crash over and over again.

    So far, only solution is to copy and paste the address.

    Please launch the Console application in one of the following ways:

    ☞ Enter the first letters of his name in a Spotlight search. Select from the results (it should be at the top).

    ☞ In the Finder, select go utilities ▹ of menu bar or press the combination of keys shift-command-U. The application is in the folder that opens.

    ☞ Open LaunchPad and start typing the name.

    Step 1

    For this step, the title of the Console window should be all Messages. If it isn't, select

    SYSTEM LOG QUERIES ▹ all Messages

    in the list of logs on the left. If you don't see this list, select

    List of newspapers seen ▹ display

    in the menu at the top of the screen bar.

    In the upper right corner of the Console window, there is a search box to filter. Enter the name of the application crashed or process. For example, if Safari has crashed, you would enter "Safari" (without the quotes).

    Each message in the journal begins with the date and time when it was entered. Select the messages since the time of the last fall, as appropriate. Copy to the Clipboard by pressing Control-C key combination. Paste into a reply to this message by pressing command + V.

    The journal contains a large amount of information, almost everything that is not relevant to solve a particular problem. When you post a journal excerpt, be selective. A few dozen lines are almost always more than enough.

    Please don't dump blindly thousands of lines in the journal in this discussion.

    Please do not post screenshots of log messages - text poster.

    Some private information, such as your name, may appear in the log. Anonymize before posting.

    Step 2

    In the Console window, clear the search box, and then select

    DIAGNOSIS AND diagnostic USE information reports ▹ user

    (not diagnose them and use Messages) in the list of logs on the left. There is a disclosure triangle to the left of the list item. If the triangle is pointing to the right, click it so that it points downwards. You will see a list of reports of incidents. The name of each report begins with the name of the process and ends with ".crash". Select the most recent report on the process in question. The content of the report is displayed at right. Allows you to copy and paste to validate all of the content, text, not a screenshot.

    I know that the report is long, perhaps several hundred lines. Please report all this anyway. If the report is only a few lines, make sure that you have disabled the search box.

    If you don't see any report, but you know, he had an accident, you have chosen diagnostic and using the list of Log Messages. INFORMATION on the USE of DIAGNOSTIC AND choose instead.

    In the interest of privacy, I suggest that, before posting, you change the UUID ' anonymous, ' a long string of letters, numbers and dashes in the header of the report, if it is present (it cannot be). "

    Please do not post other types of diagnostic report - they are very long and rarely useful.

    When you post the journal excerpt or the accident report, you might see an error message on the web page: "you have included content in your post that is not allowed", or "the message contains invalid characters." It's a bug in the forum software. Thanks for posting the text on Pastebin, then post here a link to the page you created.

    If you have an account on Pastebin, please do not select private in exposure menu to paste on the page, because no one else that you will be able to see it.

  • Could you please tell me the name of the program that plays the files (mp3) begins with V and resembles a cone orange and white?

    Could you please tell me the name of the program that plays the files (mp3) begins with V and resembles a cone orange & white?

    VLC.

    http://www.videolan.org/VLC/

  • The App Store icon (which came with my iPad) is completely absent from my iPad (but not my iPhone). How can I get that back?  I've already turned the camera market.

    The App Store icon (which came with my iPad) is completely absent from my iPad (but not my iPhone). How can I get that back?  I've already turned the camera market.

    Check yourself, if you have hidden it by setting parameters > General > Restrictions > Apps install 'off' - If you have, then again ' "should get the app to reappear

  • DFSR and files that begin with numbers

    I have a DFSR configuration and it works fine except that when I went to check if all files have been sync'd I noticed none of the files that begin with a number are replicated from the original host to the new.

    It is the filter that is in place:
    ' ~ *, master, *.tmp.
    That should not exclude these files.
    TIA
    -> brian

    Hello

    Thanks for asking this question to Microsoft Community.

    I would recommend posting your query in the TechNet Forums. The community of IT professionals in the following TechNet forum will be able to help you the best.

    http://social.technet.Microsoft.com/forums/en/winserverfiles/threads

    Hope this information is helpful and let us know if you need more assistance. We will be happy to help.

  • recently bought a new computer - which came with the demo of Windows 7 installed after my old XP.

    recently bought a new computer - which came with the demo of Windows 7 installed after my old XP. Had a conflict, and then bought a House of windows 7. My old computer has my granddaughter with Xp disc. Trying to remove XP tells me that I am not the administrator? Ms. send me XP dates which I can't install. How can I fix it? My granddaughter lives in 600 kilometres away so not an easy task from reclain the XP disc?

    Colin,
    If you are still issues here is a link on the installation of Windows 7.  It gives information on how to install Windows 7 with the removal of previous versions of Windows.

    http://Windows.Microsoft.com/en-us/Windows7/installing-and-reinstalling-Windows-7

    Mike - Engineer Support Microsoft Answers
    Visit our Microsoft answers feedback Forum and let us know what you think.

Maybe you are looking for

  • The IPad 2 air

    Can I pass air ipad 2 to 10 iOS?

  • HP Officejet 7610: Print the task remains stuck in the queue

    I want to install a 7610 Deskjet to print via WiFi on my home network to a windows PC 10. It prints pages test locally, and the computer (preferences Print - print a Test Page). It still prints the first document, but that the document never leaves t

  • Portege Z930 - SDS Partitions

    I just got a Portege Z930 and explores various things until I'm heading on installation of software, etc. I noticed that 128 GB SDD related just 100 GB of space which seemed rather restrictive. So I checked and found that the drive has four partition

  • Missing files from the Installation of Windows XP disc

    Hello, I got an installation of Windows XP Professional and the installation disc, 3 files are missing, even though I don't remember the name of the files. the laptop has been pre-installed with Windows Vista Edition Home Premium and is a Compaq CQ50

  • BlackBerry 10 SW 10.3.0.675

    Some BlackBerry apps don't open, green progress bar, then go to the home screen.Have you noticed that the permissions is not editable for these applications. Did do a battery pull.