Multiple characters in one slot of an ArrayList?

I am writing a method that extracts words from a string and returns an ArrayList with the given extracted words. I am not allowed to use the method split.
I have managed to get the characters of the input string into an array list, but I can't seem to get multiple characters into one slot of the list. Can you put multiple characters into one slot of an array list?
Here is the code for my method.
import java.util.*;
import java.io.*;
public class PS6
  public static ArrayList<Object> extract_words(String string1)
   String s1 = string1;
   char space = ' ';
   int index = 0;
   ArrayList<Object> charArray = new ArrayList<Object>(s1.length());
   for (index = 0; index < s1.length(); index++)
     char current = s1.charAt(index);
     if(current != space)
       charArray.add(current);
   return charArray;
}If I leave it like this, when I write a test program to test this method, my output is:
java ExtractWordsTest
[N, o, w, i, s, t, h, e, t, i, m, e]
Not what I want. I want [Now, is, the, time]
I thought to fix this, I could modify part of the for loop as such
int position = 0;
     if(current != space)
       charArray.add(position, current);
    else
       position++;
     } thinking that this would add all characters to the same slot in the ArrayList until it found a space. If it found a space, it would advance the slot of the ArrayList and start adding characters to that slot until it found another space. It would do this until it reached the end of the string.
But with this code, the output of the test program is
java ExtractWordsTest
[e, m, i, t, e, h, t, s, i, w, o, N]
Am I going about this in the wrong way? Is it not possible to add multiple characters to one slot of an array list?

I've been trying to account for that. I figured that it wasn't giving me the last word because it never finds a final space, which is true. When in my test program, I make the test string "Now is the time " with that extra space, the out put is [Now, is, the, time].
The problem is I don't want to put in that extra space.
I've been trying to put in another else if statement, but I'm not trying things that are correct.
I've tried the above code with
else if (current == finalChar)
     { /*trying to get it to extract the last substring and add it to the array as the last element*/
       newString = s1.substring(s1.lastIndexOf(space), s1.length());
       stringArrayL.add(newString);
     }but even though the method compiles, it makes my test program go crazy and clearly does not work.
I've tried using || in various ways, specifically regarding the second else statement
else if (current == space || current = s1.charAt(s1.length()))
         stringArrayL.add(newString);
         newString = "";
       }but that, as well as other || parameters I have tried keeps spitting out
[Now, is, the]
The only way I've gotten it to give me all four is by putting that extra space in at the end of the test string, which I don't want to have to do.

Similar Messages

  • Create a flat file with multiple characters for enclosures

    Hello,
    we use OWB 11g2 (11.2.02).
    Now we try to create a flat file with multiple characters for enclosures. The manual wrote:
    "Enclosures (Left and Right): Some delimited files contain enclosures that denote text strings within a field. If the file contains enclosures, enter an enclosure character in the text box or select one from the list. The list displays commonenclosures. However, you may enter any character. The default for both the left and right enclosure is the double quotation mark ("). You can specify multiple characters and hexadecimal characters as field enclosures."
    But it will not work. The OWB use the first character from the left enclosure definition as left enclosure and the second one as right enclosure !?!
    Did anyone know this behavior? Is there a solution for this problem?
    Thanks and regards
    Norbert

    HI Raghu,
               Use the function module 'GUI_UPLOAD'.
               In that you have to specify the field_separator value = 'X' in export section.
    Regards,
    S.C.K

  • Re-using Animation on Multiple Characters

    Hi I don't know if this is the right place to ask this, please bear with me. So in my game, I got 20 enemies that looked different, but should have the same animations. For example the dying, running, walking animations are all structured the same. But I don't want to do this manually, giving the fact that I'm using frame by frame animations, it will consume a lot of my time. Is there a way I can re-use my main animations to other movieclips/characters? Like reusing armature/animation via bone tool... thanks
    There's an old thread almost the same as mine. Saw this link, and this is the one I'm talking about. But sadly, ain't free.
    http://www.cartoonsolutions.com/store/catalog/Re-using-Animation-on-Multiple-Characters-Vi deo-Tutorial-p-16569.html

    Yes, I'm currently using FbF. But I can't show you any SS right now for the 20 enemies, cause I ain't done with that part. I only got my player's (main character) animations. Here's some of it:
    this is not drawn FbF, rather they are vector parts rotated/tweened each frame.

  • Multiple Libraries on one computer

    I want to store more music in iTunes than my iPod has room for (original iPod). I want to use one library for music that I don't want on my iPod and the other for the music I want to sync. I also want to be able to move music back and forth between the them.
    How do I store music in multiple libraries on one computer without making separate computer user accounts or using the playlist work around?
    Any ideas would be greatly appreciated. Thanks, apple-rules

    Yes, I am referring to the auto syncing of playlists. Not all of my music is assigned to playlists and I don't want to create them - too many songs.
    As I mentioned in my original post:
    I want to store more music in iTunes than my iPod has room for (original iPod). I want to use one library for music that I don't want on my iPod and the other for the music I want to sync. I also want to be able to move music back and forth between the them.
    I want to be able to store music in iTunes and play that music in iTunes without having them downloaded to my iPod. It would be nice to have a Library in iTunes that can be separate from the iPod stuff.
    I think I found a work around (#12). Until I get a better solution I am going to create a master folder to which I will move all my music that I do not want syncing to my iPod. Then, I will do a manual sync and exclude that folder.
    Thanks everyone.

  • How to use multiple ipods on one account

    I have an Ipod classic and just bought my sons two nano's how do I use these on the same account without changing my account info?

    Take a look here:
    How to use multiple iPods with one computer
    Forum Tip: Since you're new here, you've probably not discovered the Search feature available on every Discussions page, but next time, it might save you time (and everyone else from having to answer the same question multiple times) if you search a couple of ways for a topic, both in the relevant forums, in the User Tips Library and in the Apple Knowledge Base before you post a question.
    Regards.

  • Can i use multiple ipods on one account

    How do i use multiple ipods on one account so that we can share the music that we own and has been downloaded from cd's

    Just import the CD music into the libraries used by the different devices. Yo can use Home Sharing
    Understanding Home Sharing
    Troubleshooting Home Sharing
    CD music is not locked to any account

  • How to delete Multiple Artists in one action?

    Hi,
    I want to do a big clean up on an iTunes library with over 4000 albums.
    How can I delete multiple Artists in one action?
    It looks like I can only delete 1 Artist at a time, and then this action shoots me to the top of the list.  Which is a pain then having to scroll back down through such a huge list to then delete the others one at a time... each time being shot back to the top of the list.
    For example I have the following artists;
    The Alarm 01 – 1 song
    The Alarm 02 – 1 song
    The Alarm 03 – 1 song
    The Alarm 04 – 1 song
    The Alarm 05 – 1 song
    The Alarm 06 – 1 song
    And I want to delete them all in 1 action.
    Can this be done?  How best to do it?
    Thanks in advance,
    Dave

    You can't delete "artists" - just songs (or songs grouped into albums).  When iTunes displays the library or a playlist in Artists view it is doing so using the metadata values set in the relevant songs.  If you're looking at this view:
    then your selections in the left pane - the artists list - is filtering what you see on the right.  When you select Delete via the keyboard or via a right-click operation, you are initiating an operation to delete the songs by that artist.  To delete songs by more than one artist in a single operation you'll need to select and delete in Albums view:
    or in Songs view:
    where you can also use the Column Browser to filter songs by multiple artists:

  • Can there be multiple accounts on one id?

    can there be multiple accounts on one id?

    Unfortunately you can't do the logical and convenient thing of authorizing a computer with multiple Adobe IDs that are active simultaneously.
    You can authorize accounts from different vendors; one account per vendor.
    If you have multiple operating system users set up on the computer,  you can register different OS users as different Adobe Account users.

  • Ability to view multiple files in ONE window

    I can see here that this is not a new topic really but the thing with Acrobat 9 is so frustrating that it is just unbelievable.
    This is another pearl:
    Acrobat 9 "lost" its predecessors ability to view multiple files in ONE window. After opening four only documents I cannot see anything on the screen because the toolbars on each individual window cover all necessary view and nothing is left for the actual document. And sometimes I need to open 20 documents!
    This is ABSOLUTE DISASTER!!!
    I found some explanations from Adobe on the Web that are more than a year old.
    I was sure that by now this unfortunate mishandling of that feature (apparently it was dropped out from A9 deliberately - WHO'S IDEA WAS THAT?) would be somehow restorable.
    Would anyone happen to know if this feature can get restored to how it was working in A7 or 8 (without the need to uninstall A9 and install A8)?

    No, it can't be restored, unless Adobe decides to change the way Acrobat works (which is possible, but not likely).
    By the way, it was Microsoft's idea... Adobe were just following their example on this.
    You can make a feature request here: https://www.adobe.com/cfusion/mmform/index.cfm?name=wishform

  • Generate Multiple Invoices in One PDF

    Hi,
    I have requirement whereby I need to generate multiple invoices in one PDF file. I am using Oracle BI Publisher with Oracle APEX 4.0.2
    If there is only one invoice that needs to be generated in one PDF file then I already have the solution whereby I print the APEX page item session state values on Invoice Header and get the invoice line items from a SQL Query in my RTF template.
    However how to the do the same when multiple invoice needs to be generated in one single PDF file ?
    Any pointers will highly appreciated.
    Thanks & Regards,
    Ashish

    asagarwal wrote:
    However how to the do the same when multiple invoice needs to be generated in one single PDF file ?It should be pretty straight forward.
    Once you've got the query returning multiple rows, then just add a repeating group to your report (if an existing report, just select the section of the document that will repeat -> add-ins menu -> insert repeating group...; or right click selection -> BI Publisher -> Create group...), wherein the column values exist. You can even specify a page break at the end.
    By the way, this question is probably more suited for the {forum:id=245} forum.
    Ta,
    Trent

  • How do I scan multiple pages into one pdf document on a HP Envy 4501 Printer

    My HP Envy 4501 Printer won't let me scan multiple pages into one pdf document.
    I went to "Advanced Settings", clicked on "file" and made sure that the check box next to "Create a separate file for each scanner page" was unchecked.
    When I clicked the Save button it showed the page that I scanned and showed 1/1.  On the right side it had options for changing the brightness and Contrast, Rotate and Crop and "Back", "Save" and "Done" buttons, but nothing about scanning another page.
    Not to mention HP's Customer Support is useless!
    I'd appreciate any help I can get with this problem.
    Thanks,
    Mark

    Hi BH,
    I see your diagram.  I just scanned something.  The screen that I'm looking at right now shows the preview page and the scroll box to the left of that just like in your diagram.  The screen does not show the + button nor does it show the red x button under the scroll box as in your diagram.  I can't see the plus sign because it is not there.
    I tried re-installing the software and drivers as you suggested but that did not have any affect.
    Thank you for trying to help me with this problem but it hasn't worked, therefore I can't mark the reply "Accept as Solution".
    I've noticed that on HP's support forum web page there is only 1 solved request for assistance.  That doesn't give me much confidence in HP.
    Please reply back to this post to let me know if there is anything else that I can try or if you know someone else at HP that can help.
    If I don't here back from you, I'm returning this HP Envy 4501 Printer to get my money back to use it to buy a printer from one of HP's competitors.
    Thanks,
    Mark  

  • Scanning multiple pages into one document with an automatic document feeder

    when using automatic document feeder to scan in multiple pages - using the Image Capture app, this process does not work for more than 2 pages. However works perfectly in PC environment.
    Using a MacBook Pro with 10.8.4 and a Lexmark Interpret 405S All In One Scanner.
    Is there any other all in one device that can perform this function in a Mac environment?
    Please advise.

    Hi @FentyFly ,
    I see by your post that you would like to know how to scan multiple pages into one file. I would like to help you out today.
    From the HP Scan Software, click on the link for Advanced Settings, then uncheck Create a separate file for each scanned page.
    Here is a URL for how to scan and change the settings. Just select your operating system.
    Scan.
    What operating system are you using? How to Find the Windows Edition and Version on Your Computer.
    If you need further assistance, just let me know.
    Have a great day!
    Thank You.
    Please click “Accept as Solution ” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" on the right to say “Thanks” for helping!
    Gemini02
    I work on behalf of HP

  • Scanning multiple pages in one document

     I am trying to scan multiple pages in one document.  I am using a HP Envy 4501 All-in-one and running Windows 8.1.  I used to be able to do this at one point but for some reason, lately I am not able to.  I have read other posts that spoke of a "+" sign on the left side of the screen, but it is not there for me.  Also, I cannot just save the page and scan the next without having to save them under different file names.  Please advise.
    This question was solved.
    View Solution.

    Hi,
    From the HP Software click on Scan a Document or Photo and ensure the Sow Scan Preview is checked.
    Reduce the Scan Resolution into 300 or a lower resolution and press on Scan, then the add button should appear again.
    Shlomi
    Say thanks by clicking the Kudos thumb up in the post.
    If my post resolve your problem please mark it as an Accepted Solution

  • Scanning multiple pages into one file using MAC

    How do I scan multiple pages and save them into one file or document using a MacBook Pro laptop?  My printer is an HP Photosmart 7520.  When I use this printer and scan from my PC, it does allow me to scan multiple copies and save as one document by just adding pages as I scan.  When I scan with my MacBook Pro, it scans each page, however, I don't get any option or choice to save as one document.  It automatically saves each page as a separate document.

    Try scanning from your Mac. Use Image Capture app in your Applications folder.
    Click once on the scanner on the left side, then click on Show Details along the bottom. Along the right side you will see LOTS of options for scanning and saving.
    One of those is Format, make the Format PDF.  Just below that will be a check box allowing you to scan multiple pages to one file.
    Say thanks by clicking "Kudos" "thumbs up" in the post that helped you.
    I am employed by HP

  • Scanning multiple pages to one PDF file on HP PHotosmart 6525 printer

    I tried the solution but there was no box near preview so I could change DPI to 300. Tried to scan 2 documents, no save button either. Help?

    Hi nancynurse,
    Welcome to the HP Support Forums! I see you are interested in scanning multiple pages to one single PDF file and be able to change the dpi settings. To better assist you can you please leave me with the following information:
    1. What is the current Operating system you are running, Windows or Mac and which version?
    2. Which solution was it that you tried with no success?
    3. How are you scanning, with or without the HP Software?
    I hope to hear from you soon so we can begin troubleshooting!
    Thanks,
    HevnLgh
    I work on behalf of HP
    Please click “Accept as Solution” if you feel my post solved your issue, it will help others find the solution.
    Click the “Kudos Thumbs Up" to the left of the reply button to say “Thanks” for helping!

Maybe you are looking for

  • Xbox Live Port Setttings

    I have a wireless network set-up in my home which allows me to connect with my ibook or my xbox 360. In the past i've always had a firewall activated & gamed no probs but recently when trying to speak to friends, or accept game invites from them on l

  • Priority field mandatory for planning plant-order type

    Hi Is there a standard way through configuration that I may contol priority field in order header to be mandatory for some order types only in one planning plant? Problem is that if I make the priority field mandatory for order type, it will be so fo

  • Adding or deleting whole artists or albums

    How do you delete a whole artist from the iTunes library? How do you add a whole artist/album to a playlist?

  • Illustrator CC - Where are the Typekit fonts?

    One of the things I anticipated most about upgrading from Illustrator CS6 to Illustrator CC was access to the Typekit font library. The Creative Cloud application manager merely has a "coming soon" banner under the "Fonts" menu. I don't see anything

  • Why do most of my fonts in Keynote track extremely tight?

    I am using Keynote '09 (5.3) on a MacBookAir. Most any font I choose (other than the standard fonts loaded in the templates) seem to track so tightly, any word seems to appear like a blob. The font is recognizable but the kerning is like negative 100