Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 5 of 5

Thread: Different operation on Array

  1. #1
    Junior Member
    Join Date
    Jan 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Different operation on Array

    Hi guys...im having trouble with my subject in school, our professor gave us a problem and it needs Array,..
    well our topic is Insert,Search,Delete. I dont know how to insert a data in array and save it so that i can search it again, im using javax.swing,
    guys please help me thx


  2. #2
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: How to input items in array

    Hello jempot and welcome to the Java Programming Forums!

    I hope this example will help you.

    public class Jempot {
     
     public static void main(String[] args) {
     
      //Declare a String Array which can hold 5 items. 
      String[] myArray = new String[5];
     
      //Populate the Array
      myArray[0] = "John";
      myArray[1] = "Rosie";
      myArray[2] = "Mark";
      myArray[3] = "Steve";
      myArray[4] = "Natalie";
     
      //Loop through the Array and print its content.
      for(int a = 0; a < myArray.length; a++){
       System.out.println(myArray[a]);
      }
     
      //Print just one Array value
      System.out.println("\n" + "myArray[2] value is: " + myArray[2]);  
     }
    }
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

  3. #3
    Junior Member
    Join Date
    Jan 2009
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to input items in array

    ok i got this one thx...
    but you already populate it in the array,... im wondering if the user going to input items in it and save it?...what am i going to use if i continually save an item in array??

  4. #4
    Junior Member
    Join Date
    Dec 2008
    Location
    london
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Re: How to input items in array

    import java.io.*;
    public class ArrayRead 
    {
        public static void main(String[] az)throws IOException
        {
            String s[]=new String[5];
            System.out.println("Enter theStrings");
            BufferedReader b=new BufferedReader(new InputStreamReader(System.in));
            for(int i=0;i<5;i++)
                s[i]=b.readLine();
            for(int i=0;i<5;i++)
                System.out.println(s[i]);
        }
    }

  5. #5
    mmm.. coffee JavaPF's Avatar
    Join Date
    May 2008
    Location
    United Kingdom
    Posts
    3,336
    My Mood
    Mellow
    Thanks
    258
    Thanked 294 Times in 227 Posts
    Blog Entries
    4

    Default Re: How to input items in array

    Quote Originally Posted by jempot View Post
    ok i got this one thx...
    but you already populate it in the array,... im wondering if the user going to input items in it and save it?...what am i going to use if i continually save an item in array??
    Take a look at vigneswaras example. Good work.

    He is using a buffered reader to take user input from the console.

    This can also be done using the Scanner class. Here is an example:

    http://www.javaprogrammingforums.com...ner-class.html
    Please use [highlight=Java] code [/highlight] tags when posting your code.
    Forum Tip: Add to peoples reputation by clicking the button on their useful posts.

Similar Threads

  1. Replies: 1
    Last Post: November 2nd, 2012, 02:21 PM
  2. Reading user input from the console with the Scanner class
    By JavaPF in forum Java SE API Tutorials
    Replies: 3
    Last Post: September 7th, 2011, 03:09 AM
  3. Object creation from a input file and storing in an Array list
    By LabX in forum File I/O & Other I/O Streams
    Replies: 4
    Last Post: May 14th, 2009, 03:52 AM
  4. How to check that console input should be integer only?
    By Konnor in forum File I/O & Other I/O Streams
    Replies: 3
    Last Post: February 2nd, 2009, 05:37 AM
  5. Program to mask input
    By sah in forum Java Theory & Questions
    Replies: 1
    Last Post: January 26th, 2009, 06:43 PM