Finding a position of an item in a list.

What i am looking to do is find the position of an item in a list. for instance if my list contains [a, b, c, d, e] and on my command line i put a f d, i want it to return a value of 3 for the position of the 'd' in my list. Could anyone please advise the best way to complete this? I think i am having the problem of it recognizing the 'd'. I would appreciate any help. Here is a piece of my code.
import java.io.InputStreamReader;
import java.util.LinkedList;
import java.util.Scanner;
public class LinknedList {
     public static void main(String args[]) {
          Scanner scanner = new Scanner(new InputStreamReader(System.in));
          // Setting up the link list of strings
          LinkedList<String> list = new LinkedList<String>();
          // MyLinkedList myList = new MyLinkedList();
          while (scanner.hasNext()) {
               char option = scanner.next().charAt(0);
               option = Character.toLowerCase(option);
               switch (option) {
               // inserts to end of list
               case 'i':
                    if (scanner.hasNext()) {
                         String value = scanner.next();
                         list.addLast(value);
                         // myList.addLast(value);
                    } else {
                         System.out.println("ERROR: Unexpected end of input \"a\"");
                    break;
               case 'r':
                    if (!list.isEmpty()) {
                         System.out.println("Removed: " + list.removeFirst());
                    } else {
                         System.out.println("ERROR: List was empty");
                    break;
               case 'p':
                    System.out.println(list.toString());
                    break;
               case 'a':
                    if (scanner.hasNext()) {
                         String value = scanner.next();
                         list.add(0, value);
                    } else {
                         System.out.println("ERROR: Unexpected end of input \"a\"");
                    break;
               case 'd':
                    list.clear();
                    System.out.println("Your list has been deleted.");
                    break;
               case 's':
                    int num = list.size();
                    if (num == 0) {
                         System.out
                                   .println("The list does not have any items in it.");
                    } else
                         System.out.println("Your list is " + num + " items long.");
                    break;
               case 'f':
                    // need to find the position of an letter on the command line
                    break;
               default:
                    System.out.println("Not an option: " + option);
                    break;
               System.out.println("Java: " + list.toString());
               System.out.println("Mine: ");
}

What i am doing is building a Linked List. It will have a standard input. you have multiple commands. i, a, d, p, s, f. i will insert, a will add, d will delete, p will print, s will display amount of items on the list and f will set the position in the list. For example. if i type:
a john
the result will be:
[john]
a paul
the result will be:
[jon, paul]
Lets say i have the list with the items [jon, paul, ringo, geroge] in it and i choose:
f paul
a stuart
the result will be:
[jon, paul, stuart, ringo, george]
I want the f switch statement to make a new point in the list where the new item will be added.

Similar Messages

  • How to get current displayed position of an item in listcontrol ?

    Hi,
    can anyone please help me to get current displayed position of an item in a listbox control in vc++ mfc. I am using CListCtrl class to manipulate.
    Thanks,
    saffiuddin 

    On 4/11/2015 3:45 AM, "David Lowndes [MVP]" wrote:
    can anyone please help me to get current displayed position of an item in a listbox control in vc++ mfc. I am using CListCtrl class to manipulate.
    Have you tried GetItemPosition?
    ... or GetItemRect (a bit more information).
    Igor Tandetnik

  • Finding the position of the end of a line in a JTextPane

    I'm trying to make a JTextPane which expands horizontally if the text being typed in it reaches the right hand edge. To do this I need to know the position in the Document of the end of the current line.
    I've managed to write a method which expands the JTextPane vertically using getEndPosition() in AbstractDocument.
    There is an endLineAction in the DefaultEditorKit which moves the Caret to the end of the line but I don't want to move the Caret, just find the position of the end of the line. I did have a method before which moved the Caret to the end of the line, stored the position and moved it back but that wasn't suitable.
    I suspected the answer was to do with the View but I can't figure out how the View relates to the JTextPane or Document.
    Can anyone help?

    Well, personally I don't think its a good idea to keep changing the size of the text pane as text is being typed and I doubt the solution will be as easy as you think.
    As you type the text will automatically wrap so it will be a little late trying to change the width after the text has wrapped, which means you would need to increase the width "before" text is typed. But then you have another problem because you don't know how much to increase the width by since a single character could be typed or a string of text could be pasted into the text area (people always forget about pasting when doing stuff like this).
    Also if text is removed you would need to iterate through all the line to find the longest line and reset the width.
    Anyway the only way to know the width would be to play with the modelToView() method. If you want to find the end of the current line then you can use the Element.
    Check out my [Text Utilities|http://www.camick.com/java/blog.html?name=text-utilities] class which might give you some ideas on how to use the Element class and modelToView() method.
    which has example of using the above Class and method that might give you some ideas.

  • How to find the position of view in MM02 transaction for coding BDC?

    Hi Guys,
    Is there any FM or BAPI Available to find the position of the view in MM02 transaction. I tried FM SELECTION_VIEWS_FIND. But getting inconsistent results
    i.e Some materials it is giving correct positions but for others i am getting wrong position. So my BDC is getting failed.
    Thanks in advance.
    Vinod.

    Hi,
    data : i_t133a like t133a occurs 0 with header line,
          ch(1),
           viewno(2) type n.
    clear viewno.
      select * from t133a into corresponding fields of table i_t133a
                    where bilds = '21' and guifu like 'SP%'  .
      loop at i_t133a .
        ch = i_t133a-pstat.
        if mara-vpsta na ch .
          delete i_t133a     .
          continue .
        endif .
      endloop.
      sort i_t133a by guifu ascending .
      loop at i_t133a .
        viewno = viewno + 1 .
        if i_t133a-guifu = 'SP01'.  "FOR BASIC DATA1                CHANGES              ACCORDINGLY REFER TABLE T133A TO FIND VTHE VALUE
          exit .
        endif .
      endloop .
    reward if usefull

  • How can I find the position of a robotic arm with a cFP-CTR card?

    Hello,
    I use a CTR-500 to measure the pulses of 3 encoders.
    The encoders are related to the 3 axis (x,y,z), to which a robotic arm is moving.
    Each encoder has 2 channels (A,B) which go to each pair of Count Inputs of the CTR card.
    When the robotic arm is moving on one axis, the corresponding pair of Count Inputs is increasing, but there is a phase between the one Count Input and the second one. What is more, the Count Inputs do not decrease when the robotic arm is moving to the other direction, but they still increase.
    So, I cannot find easily the position of the robotic arm.
    What I have done, is to try finding the position, by using only one Counter Input for each axis. This means that I use the value of the encoder as a counter, and I calculate the position with some software tricks. But for some reason, it does not work properly.
    I have heard that the method I use is not proper. Instead, I have been told that I must use the phase of the 2 Count Inputs, in order to find the direction to which the robotic arm is moving. But, the Count Inputs of the CTR are augmenting in parallel, when the robotic arm is moving forward or backward.
    How can I find the position of the robotic arm, as it is moving like a CNC ?
    Thank you very much.
    Message Edited by nikosfs on 08-21-2009 12:27 PM

    You don't want to use a cFP-CTR-500 card.  What you have are quadrature signals.  You should be using the cFP-QUAD-510.  It has 4 channels that can handle both the A and B signals of a quadrature encoder.  It has the built in circuitry do determine the phasing of A vs. B to know when to count up vs. count down.

  • Need help in finding the position of a SubString in a String

    Hi All,
    I have a VARCHAR2 column in my table which has data similar to '152-425-3265-8-5623-45'.
    I want to find the position of the numbers in the column.
    For example:
    If i give 8 - query should return me 4.
    If i give 425 - query should return me 2.
    The numbers are delimited with '-' value.
    Please help.
    Thanks in advance.
    Edited by: 868171 on Jun 24, 2011 4:33 AM
    Edited by: 868171 on Jun 24, 2011 4:34 AM

    do you know the max number of dashes?
    if so
    with t as (select  '152-425-3265-8-5623-45' code, '425' num from dual union
                   select  '152-425-3265-8-5623-45' code, '8' num from dual)
    select code, num, case num when  regexp_substr( code,'[^\-]+',1,1) then '1'
                   when  regexp_substr( code,'[^\-]+',1,2)  then '2'
                   when  regexp_substr( code,'[^\-]+',1,3) then '3'
                   when  regexp_substr( code,'[^\-]+',1,4)  then '4'
                   when  regexp_substr( code,'[^\-]+',1,5) then '5'
                   when  regexp_substr( code,'[^\-]+',1,6)  then '6'
                   else 'not found' end result
    from t
    CODE     NUM     RESULT
    152-425-3265-8-5623-45     425     2
    152-425-3265-8-5623-45     8     4or if you have 11g you can use regexp_count
    with t as (select  '152-425-3265-8-5623-45' code, '425' num from dual union
                   select  '152-425-3265-8-5623-45' code, '8' num from dual)
    select code, num, regexp_count(regexp_substr(code,'^.*'||num||'.'),'-')
    from tEdited by: pollywog on Jun 24, 2011 7:55 AM

  • Changing the position of graphic item

    Hi all,
    I am using graphical items in my form canvas. I want to change the position of these items in runtime.
    can any one suggest me how to change the positions at run time.?.....
    Thanks,
    Pavan.

    Hello,
    This question has been aked so many times, and the answer is always the same : NO
    There is no available buit-in to deal with graphical objects located on the canvas. All you can do is to drop them on a small stacked-canvas, then move this stacked-canvas.
    Francois

  • N8 GPS can't find my position

    Hello
    I have a big problem with my N8 GPS. I just use Integrated GPS in positioning methods and I disabled A-GPS, Network and Wi-Fi options. But Ovi Map 3.04 can't find my position. I compare my phone with an N79 and a 5800 in similar situation. They can easily find the position in less than a minute! But my N8 still searching and searching…. . It’s embarrassing!!!
    Can anybody help me?! Any suggestion?

    Grrr ! All that "experts" here...
    1, Use AGPS if you want to get a coarse estimation of your position.
    2. Use internal GPS only if you want to get a precise position.
    3. There are no (NO !) differences in position fix speeds caused by software. GPS works in a sequential way: A sequential data stream is sent by the satellites. To get a full position fix, all of that data stream has to be received, from start to end. THIS causes speed differences: If you start the GPS application at the beginning of the data stream, fix is fast. If you start it in the middle of the stream, the device has to wait for the stream starting again from the beginning. This is for collection "almanach" data - data about where the satellites are at present - they're moving.
    4. If that almanach data was received earlier and no too long ago, GPS fix is fast because the device does not have to wait for that almanach data stream. Again: It has NOTHING to do with different software.
    By the way: This is what AGPS does - downloading that almanach data via internet instead of waiting to get that data via the air and trying to triangulate your coarse position with the help of comparing the signal strengths received by different cell towers. Again: This does NOT provide you with precise positioning data - just estimations. Never use AGPS if you need a reliable position fix. .
    5. GPS signals are high frequency signals. Reception of such signals may vary greatly with the phone's position: One or two cm of placing difference may cause a big change in reception.
    6. GO OUT ! Do NOT try the GPS module indoors. You MAY get sufficient signal strength inside buildings - but this is an exception, not the rule.
    7. N8s GPS receiver is really fine, very sensitive. No problem with that.
    In short: Go outside. Don't use AGPS or network-based GPS. Don't believe people saying "Precise (!) GPS fix is much faster with software blabla..." Don't get fooled by a quick display of an estimated position: The real position fix did not get calculated at that point of time; it's still running in the background. This is what's causing that constant change of your position right after the first fix got displayed. A minute later, your position appears stable; and that's the point of time where real positioning data are used - not just coarse estimations.
    It all depends on that almanach data and a clear view of the sky.

  • Cannot find the ''Positioning Methods'' option on ...

    Hello....I have recently bought the C7-00 and I wanted to test my GPS but I could not find the "Positioning Methods'' option to select the A-GPS, so can anyone help on this.
    Thank you.

    Do you not have a Location app in your Applications Folder ? As CJ mentioned , that is where you set your location methods to on/off. Inside Location you should have 3 sub folders, Landmarks,GPS data and Positioning. Open Positioning and you should be able to change the settings !
    If I have helped at all, a click on the White Star is always appreciated :
    you can also help others by marking 'accept as solution' 

  • I can't find the image object menu item when trying to add an image placeholder in dreamweaver cs6

    I am new to dreamweaver, and am walking through some tutorials.  I can't seem to find the image object menu item to place a image placeholder on my page.  Any suggestions?  Do I have a setting that is currently hiding its visibility?  Thanks  (I am currently working with dreamweaver cs6)

    They removed it in the new Cloud version of DW CS6.
    http://blogs.adobe.com/dreamweaver/2012/10/dreamweaver-creative-cloud-update-12-1-faqs.htm l

  • Relation ship code for finding manager position..

    Hi Experts,
    How to find the relationship code for finding Manager position of France and US.
    i know that
    A012 is the relationship code for France,
    What should be the relationship code for US?
    Thanks in advance.

    Hi
    If you take tables QMEL & DRAW / DRAW & QMFE
    if u have created a document in CV01N, with the object link has notification... Then you will be able to able both these tables...
    Document will be displayed...
    Both has same relationships.... you have to maintain the notification in document management system.
    Check out the linking details in SPRO - Cross-Application Components - Document Management - Control Data - Define Document types
    - Pithan

  • HT4859 how do you see the items that are backed up to iCloud -  I have 4.5 GB that I have used but I cant find where to see those items...help

    how do you see the items that are backed up to iCloud -  I have 4.5 GB that I have used but I cant find where to see those items...help

    That is everything in your iCloud account.  Videos and camera roll photos are only included in your backup, the size and content of which you can see on your phone in Settings>iCloud>Storage & Backup>Manage Storage>tap the name of your device under Backup.  This will show you the size of "Camera Roll", where these are contained.  (You can't see any detail beyond that.)  Photo stream photos can only been seen in your photo stream album on your phone, and they don't count against your storage so they aren't part of the 4.5 GB.  Everything esle is either in the backup, the items listed in Settings>iCloud>Storage & Backup>Manage Storage, or on icloud.com, where you can see your contacts, calendars, etc.

  • How Do I Reset The Finder Windows Positions?

    Hi,
    I would like to "reset my finder windows positions". Anyone knows how I can do that?
    Thanks.
    Ed

    So I cannot edit the .DS_Store file?
    You can try, as I do not know how good you are at working with binary files.  When I try to edit a .DS_Store on my system I see:
    ^@^@^@^ABud1^@^@p^@^@^@^H^@^@^@p^@^@^@^P^L^@^@h^K^@^@
    lots and lots of ^@ with occasional other characters mixed in.
    So what will it happen if I delete the .DS_Store file? Will my iMac's all Finder Windows be reseted?
    The Finder will forget information about that Folder.  Where it is positioned on the screen, how the files in the folder are arranged, etc...
    If you are concerned, create an experimental folder, put some junk files in the folder (stuff you can delete later).  Arrange things in the experimental folder, play with the size of the experimental folder.
    Now delete the .DS_Store for that file.  See what happens in a safe experimental way.  If you like the results, apply the same to folders you want to reset.
    "for each Folder", what do you mean?
    If you want to reset more than 1 folder, you would repeat the .DS_Store for each folder that you are interested in resetting.

  • Maps not finding my position

    Hi everyone
    I have a wifi model 64gb and it's impossible having maps application an other localisation working properly.
    It's impossibile finding my position on the map and afte a while i have the "unable to find your position" Message.
    I tried different networks. With or without Apple ruoters
    I tried to register networks to skyhook
    No luck.
    On the sane networks iPod touch 2g works perfectly.
    It's an iPad problem, i'm sure
    Please help me....
    Thanks a lot

    I had the same problem with my iPad 16g not being able to use any of its location services.  I finally did something crazy.  I was using a 2Wire Gateway from ATT for my wireless network and I got the idea to try something a little different.  I had just recently moved to a new house and still had my old NetGear wireless router, so I plugged my NetGear router into my 2Wire router.  My NetGear is receiving its signal from the 2Wire Gateway, but it is also broadcasting a wireless signal as well.  I took my iPad and connected to the NetGrear signal and guess what?  My iPad was able to locate my location.  Apparently, the NetGear router "transmits" some sort of "location" information that the iPad was able to read.  You might try using a NetGear router for your iPad, or another router in general.  Let me know if this helps.
    nx2000a

  • How do I download updates for my apps in iTunes 11.0?  I can't find a button or menu item anymore?

    How do I download updates for my apps in iTunes 11.0?  I can't find a button or menu item anymore?

Maybe you are looking for