How do you store input from keyboard into a string array

I am trying to learn java and one of the programs I am trying to write needs to be able to accept a machine hostname at the keyboard and stuff it into a string array element. I am sure I will be using something along the lines of:
BufferedReader in = new BufferedReader(new InputStreamReader(
                         System.in));
               String str = "";
               System.out.print("Enter a FQDN to look up: ");
               str = in.readLine();
but how do I get the input stuffed into hostname[ ].
Any hints or assistance will be appreciated.
Michael

Well part of. I need to be able to take a random number of hostnames (ie. mblack.mkblack.com, fred.mblack.com, joe.mblack.com, ...) and after the user presses the enter key between each entry, the inputted information is stored in an array element. for example with the three shown above the array would look like this after the user finished.
hostname {"mblack.mblack.com","fred.mblack.com","joe.mblack.com"};
the algorithm would be
Prompt for hostname
get user input and press enter
store hostname into array element
prompt for next hostname or enter with no input to complete entry and execute lookup.class methods.
I have the program written and working fine if I use a static array where I put the hostnames in the list, but cannot figure out how to get the information from the keyboard to the array element.
Thanks for the help though, the response is very much appreciated.
Michael

Similar Messages

  • How do you insert a carriage return into a string ?

    Hi,
    I don't know how to insert a carriage return, \n ,into a string
    without the carriage return being interpeted. I am trying to build
    a string called queryVariable from the file below so that it equates
    to the necessary format for JDBC to execute the query.
    SQL script file:
    declare @x datetime
    select @x = null
    exec OSVBAK01...demand_dump PRODUCT,FULL,@x
    go     
    required string format for query:
    "declare @x datetime\n"+"select @x = null\n"+
    "exec OSVBAK01...demand_dump PRODUCT,FULL,@x";     
    void Readfile(String path, String infilename) {
    try {
    File file = new File(path + infilename);
         if (!file.exists()) {
         System.err.println("File not found");
         BufferedReader in = new BufferedReader
    (new FileReader(file));
         String str;
         String queryVariable = "";
         StringBuffer sb = new StringBuffer();
         while ((str = in.readLine()) != null) {
         sb.append("\"").append(str).append("\n\"")
    .append("+");                              
         in.close();
         queryVariable = sb.toString();
         System.out.println(queryVariable);
    } catch (IOException e) {
         System.err.println(e.getCause());
    queryVariable equates to the following after running the code above:
    "declare @x datetime
    "+"select @x = null
    "+"exec OSVBAK01...demand_dump PRODUCT,FULL,@x
    "+"go     
    "+
    Any assistance anyone could provide would be greatly appreciated.
    Thanks for your time,
    YAM-SSM

    Interesting... that would mean, of course, that in the case of concatenating string literals (outside of loops, as they say), the compiler is optimizing the code to avoid the need for using StringBuffers internally. Actually, it's good to know this, as I wasn't aware of this optimization.
    However, the post wasn't meant to be serious... I hoped that was obvious. Everyone's spouting off nearly the same thing for adding strings and line separators and whatever.

  • How do i get something from keyboard into primitive data type such as int

    Hi guys,
    How do i store a value that was accepted via keyboard into a int variable.
    The method i tried to use was readInt of DataInputStream class which allows me enter some number then enter some number again and when i print the value stored in the variable, which is suppose to be what i entered, it prints a junk number.

    import java.io.*;
    public class Read {
         public static void main( String [] args ) throws Exception {
              BufferedReader br = new BufferedReader( new InputStreamReader( System.in ) );
              System.out.print( "Integer: " );
              String integer = br.readLine();
              int i = Integer.parseInt( integer );
              System.out.println( "i = " + i );
              br.close();
    }

  • How can you copy information from Safari into Pages

    Is there a way to easily copy data, such as financial tables from Safari into Pages and maintain the integrity of the table and the data within it?  When I copy and paste it comes out all misaligned and into multiple pages.  The same thing happens if I try to highlight the table in Safari and drag it into Pages.  Is there not a "paste special" function in Pages like there is in Microsoft??

    See:
    http://support.apple.com/kb/HT5775
    You can then drag the resulting image into a Pages document, and position.
    Ernie

  • How do you stop pictures from going into different rolls?

    Everytime I transfer a picture into iPhoto it goes into a different roll. When it comes to finding these pictures, it can take a long time. Can anyone tell me how to make pictures all go to the same place?

    Each import creates a new roll. You can't change this behavior.
    You can edit your rolls. Select Library from the Source Pane. Go to View > Sort Photos > by Film Rolls. If rolls are closed you can Option-click on one roll's disclosure triangle to open all of them at once. Open the info pane at the lower left of the iPhoto window. Now any time you select a roll by clicking its title, you can edit its info in the info pane. You can edit the title, date, and comments. You can select photo(s) and move to another roll by dragging until a roll's title is highlighted, then drop. You can combine rolls or create new rolls.
    I use large memory cards with my camera and import photos little by little, as I take them. I keep the photos from one card together in one roll. So each time I import, I immediately drag the new roll up to the existing roll for that memory card. This places those photos into the roll with the others, and deletes the newly created roll.

  • How do you transfer songs from ipod into itunes library

    I have recently purchased an apple mac and am trying to transfer my songs (which I previously uploaded from CD's) to the itunes library but with no success.  does anyone know how to do this?  Thanks

    Some of the information below is summarized by turingtest2 in the post at https://discussions.apple.com/message/18842615
    Your i-device was not designed for unique storage of your media. It is not a backup device and media transfer is designed for you maintaining a master copy of your media on a computer which is itself properly backed up against loss. Syncing is one way, computer to device, updating the device content to the content on the computer, not updating or restoring content on a computer. The exception is iTunes Store purchased content.
    iTunes Store: Transferring purchases from your iOS device or iPod to a computer - http://support.apple.com/kb/HT1848 - only media purchased from iTunes Store
    For transferring other items from an i-device to a computer you will have to use third party commercial software. Examples (check the web for others; this is not an exhaustive listing, nor do I have any idea if they are any good):
    - Senuti - http://www.fadingred.com/senuti/
    - Phoneview - http://www.ecamm.com/mac/phoneview/
    - MusicRescue - http://www.kennettnet.co.uk/products/musicrescue/ - Mac & Windows
    - Sharepod (free) - http://download.cnet.com/SharePod/3000-2141_4-10794489.html?tag=mncol;2 - Windows
    - Snowfox/iMedia - http://www.mac-videoconverter.com/imedia-transfer-mac.html - Mac & PC
    - iexplorer (free) - http://www.macroplant.com/iexplorer/ - Mac&PC
    - Yamipod (free) - http://www.yamipod.com/main/modules/downloads/ - PC, Linux, Mac [Still updated for use on newer devices? No edits to site since 2010.]
    - 2010 Post by Zevoneer: iPod media recovery options - https://discussions.apple.com/message/11624224 - this is an older post and many of the links are also for old posts, so bear this in mind when reading them.
    Syncing to a "New" Computer or replacing a "crashed" Hard Drive - https://discussions.apple.com/docs/DOC-3141 - dates from 2008 and some outdated information now.
    Copying Content from your iPod to your Computer - The Definitive Guide - http://www.ilounge.com/index.php/articles/comments/copying-music-from-ipod-to-co mputer/ - Information about use in disk mode pertains only to older model iPods.
    Get Your Music Off of Your iPod - http://howto.wired.com/wiki/Get_Your_Music_Off_of_Your_iPod - I am not sure but this may only work with some models and not newer Touch, iPhone, or iPad.
    Additional information here https://discussions.apple.com/message/18324797

  • How can you transfer music from itunes into another mp3 player

    I have an iriver for which I want to load music and leave it at work. how can I copy musci to that device?

    You can't. The iPod software is for iPod's only. Makes sense. Whatever software you use with your iRiver, use that.

  • How do you import photos from iPhoto into lightroom?

    I have lightroom 5.7 and OX10.9.5 if it matters.  I can't find the iPhoto photos and dragging them in doesn't do anything. 

    Either Lightroom Help | Import photos from iPhoto (Mac OS)
    or this plug-in (yes it says Aperture but it works for iPhoto too): Aperture import plugin now available

  • How do you choose songs from your ipod instead of from the car dashboard while your ipod is plugged into your car?

    How do you choose songs from your ipod instead of from the car dashboard while your ipod is plugged into your car?

    It depends on your car stereo. On the JVC we have you can select either "Head Mode" or "iPod Mode" when you're plugged into the USB port. Ipod Mode lets you select the songs from the iPod although the radio still controls the volume. I believe the Alpine I have does the same thing.

  • How do you edit photos from lightroom 5 into elements 12

    how do you edit photos from lightroom 5 into elements 12 in the prefrences it dosent show elements 12 only cs5 i cant work out why help please

    Hi,
    For Windows, in Lightroom preferences for external editing, have you added a custom setting for the elements 12 editor?
    Click on the Choose button and navigate to the editor
    "C:\Program Files (x86)\Adobe\Photoshop Elements 12\PhotoshopElementsEditor.exe"
    [omit the (x86) if on 32bit system]
    Brian

  • HT3775 how do you import movies from an i-kam xtreme eyewear video camera hunting glasses into imovie?

    how do you import movies from an i-kam xtreme eyewear video camera hunting glasses into imovie?

    Here you go Karsten:
    http://www.hunterspec.com/content/i-kam-xtreme®-video-eyewear-0
    Looks like it records in AVI format at 25 fps. I think that should import to iMovie OK - if not it should import to iPhoto and then be available in the iMovie Events Library under "iPhoto Videos". Importing shouldn't be a problem based on this extract from the web page:
    "The glasses can be hooked directly to a PC with the supplied USB cable to view the video, or when using the Micro SD card, it can be inserted into a card reader to watch footage."
    John
    EDIT: Also, see this point under Features: "Easy PC/Mac USB Connection (no driver needed)"
    Message was edited by: John Cogdell

  • How do you change service from your old LG phone to a iPhone 4S without going into pioneer

    How do you change service from your old LG phone to a iPhone 4S without going into pioneer

    I would call Pioneer and ask them if you can do that.

  • How do you recoup software from the app store after a crash?

    How do you recoup software from the app store after a crash? It's not like the old days when you bought software on CDs.

    Mac App Store: Frequently Asked Questions (FAQ) - http://support.apple.com/kb/HT4461

  • How do you post photos from IPhoto to Facebook as individual stories? NOT AS AN ALBUM?

    How do you post photos from IPhoto to Facebook as individual stories? NOT AS AN ALBUM?

    That is FaceBook software and the way it works.
    https://www.facebook.com/help/
    You can  wait a day before you post a second photo,
    or create your own album which only includes 1 photo/ album

  • I would like to know how do I install the brazilian keyboard into macbook air, keyboard with accents (Portuguese Language), I tried so many times how to put into it (Macbook Air). So, thanks for now! I'm waiting for it.

    I would like to know how do I install the brazilian keyboard into macbook air, keyboard with accents (Portuguese Language), I tried so many times how to put into it (Macbook Air). So, thanks for now! I'm waiting for it.

    After you go to system preferences/keyboard/input sources as suggested by sberman, click on the + button and scroll down to Portuguese and select that.  Over at the right you will see the choices Brazilian, Brazilian abnt, Portuguese.  You might want to add all three to see which you like best.
    The "Brazilian" layout is pretty useless.  It is identical to the US layout and the only way to make accents is via the option key shortcuts:  option + n, then o gives you õ.
    The Brazilian abnt and Portuguese layouts have dead keys for adding accents over at the right edge of the keyboard.  But these may not match what is printed on your keys.
    You may prefer to stay with the US layout.  On that you can get accented letters by just holding down the base letter and selecting what you want from the popup menu that appears.  Or you can use the option key shortcuts.
    Another option is the layout called US International PC, which has accent deadkeys on ~, ', etc.
    Which ever layout you want to use, you must select it in the "flag" menu at the top right of the screen.
    To see which key does what for any layout, use the Keyboard Viewer:
    http://support.apple.com/kb/PH13746

Maybe you are looking for