NEED A PROG

NEED A PROG

whats the program to add,delete, display elements of an object using collecions. without using linked list

View Answers

December 27, 2010 at 12:37 PM

Hi Friend,

Try the following code:

import java.util.*;
class CollectionExample
{
    public static void main(String[] args) 
    {
        ArrayList list=new ArrayList();
        Scanner  input=new Scanner(System.in);
        System.out.println("Enter List Elements: ");
        for(int i=0;i<5;i++){
            String st=input.next();
            list.add(st);
        }
        System.out.println();
        System.out.println("List Elements are: ");
        for(int i=0;i<list.size();i++){
            System.out.println(list.get(i));
        }
        System.out.println();
        System.out.println("Enter the index of element to remove: ");
        int index=input.nextInt();
        list.remove(index);
        System.out.println();
        System.out.println("Now the list is: ");
        for(int i=0;i<list.size();i++){
            System.out.println(list.get(i));
        }
        System.out.println();
        System.out.println("Enter the index of new element to add: ");
        int in=input.nextInt();
        list.add(in,"RoseIndia");
        System.out.println();
        System.out.println("Now the list is: ");
        for(int i=0;i<list.size();i++){
            System.out.println(list.get(i));
        }
    }
}

For more information, visit the following links:

http://www.roseindia.net/javacodeexamples/index.shtml

http://www.roseindia.net/java/jdk6/

Thanks









Related Tutorials/Questions & Answers:
NEED A PROG
NEED A PROG   whats the program to add,delete, display elements of an object using collecions. without using linked list   Hi Friend, Try the following code: import java.util.*; class CollectionExample { public
(ForPro) turbo C prog. Q4
(ForPro) turbo C prog. Q4  I need to learn some easy foxpro program.. for example sum,interchange, loop etc
Advertisements
turbo C prog.
turbo C prog.  Is is possible print ASCII value of a alphabets using turbo C prog
ModuleNotFoundError: No module named 'prog'
ModuleNotFoundError: No module named 'prog'  Hi, My Python program is throwing following error: ModuleNotFoundError: No module named 'prog' How to remove the ModuleNotFoundError: No module named 'prog' error
need
need  i need a jsp coding based project plz help me
java prog que
java prog que  create a class that returns the reverse of each word in the given string. For example if we give "who are u?" as input, it should return "ohw era u
question "writing prog"
question "writing prog"  Hello I want helping for this question, please Write a program that reads some friendsā?? names, stores them in an array, and then prints out on the screen all friends who start by a particular letter
please help me in these prog
please help me in these prog   create 2 jdbc programs including awt create 2 jdbc programs including swing create 2 jdbc programs including command line argument create 2 jdbc programs including io class 4 jdbc prog using
Solution to C prog
Solution to C prog   Hi, Pls any body help, why the following prog crashing while running. #include<stdio.h> #include<conio.h> int main(){ int n,*fact(int *n); printf("Enter the number:"); scanf
ModuleNotFoundError: No module named 'func_prog'
ModuleNotFoundError: No module named 'func_prog'  Hi, My Python... 'func_prog' How to remove the ModuleNotFoundError: No module named 'func_prog' error? Thanks   Hi, In your python environment you
servlet prog - Java Interview Questions
servlet prog  how to forward or redirect the client request from servlet to jsp? how a thread or request pass from one servlet prog to one jsp prog? is it possible of communicating from servlet to jsp prog? please explain briefly
make a prog for this query
make a prog for this query  write a program implementing interface for personal data n salary details. interface must contain abstract methods. steps for the program are 1) store the data in text file 2)display salary when emp id
turbo C prog.
turbo C prog.  Is it possible to print ASCII value A to Z with out using scan ? also give to simple example of binary search ...   #include<stdio.h> #include<conio.h> void main() { for(char c='A';c<
Prog Error - JSP-Servlet
Prog Error   Place Ad function Browse() { Advertisement Management System Create Ad State: City: Main Category: Sub Category: Title
Java entry prog.
Java entry prog.  Dear sir I will enter the dept code, dept name and insert into dept_mast and save. Pl. Dept_mast Dept_code Char(2) Primary key (no duplicate key allowed) Dept_name Char(25
turbo C prog. Q3
turbo C prog. Q3  What is the difference between if and ladder if ? Describe ladder if with example. What is the purpose of the parameter passing ? please Describe with example.   if statement is used to write
ModuleNotFoundError: No module named 'prog-edu-assistant-tools'
ModuleNotFoundError: No module named 'prog-edu-assistant-tools'  Hi...: No module named 'prog-edu-assistant-tools' How to remove the ModuleNotFoundError: No module named 'prog-edu-assistant-tools' error? Thanks  
ModuleNotFoundError: No module named 'prog_lang_detector'
ModuleNotFoundError: No module named 'prog_lang_detector'  Hi, My... named 'prog_lang_detector' How to remove the ModuleNotFoundError: No module named 'prog_lang_detector' error? Thanks   Hi, In your
Spring Hello World prog - Spring
Spring Hello World prog  I used running the helloworld prog code mentioned in http://www.vaannila.com/spring/spring-mvc-tutorial-1.html I'm getting null pointer exception. as shown below. I added all the jars and my
PKG_PROG_PKG_CONFIG: command not found
PKG_PROG_PKG_CONFIG: command not found  Hi, How to solve PKGPROGPKG_CONFIG: command not found error This error is coming while executing the configure script. Thanks
PKG_PROG_PKG_CONFIG: command not found
PKG_PROG_PKG_CONFIG: command not found  Hi, How to solve PKGPROGPKG_CONFIG: command not found error This error is coming while executing the configure script. Thanks
PKG_PROG_PKG_CONFIG: command not found
PKG_PROG_PKG_CONFIG: command not found  Hi, How to solve PKGPROGPKG_CONFIG: command not found error This error is coming while executing the configure script. Thanks
PKG_PROG_PKG_CONFIG: command not found
PKG_PROG_PKG_CONFIG: command not found  Hi, How to solve PKGPROGPKG_CONFIG: command not found error This error is coming while executing the configure script. Thanks
PKG_PROG_PKG_CONFIG: command not found
PKG_PROG_PKG_CONFIG: command not found  Hi, How to solve PKGPROGPKG_CONFIG: command not found error This error is coming while executing the configure script. Thanks
java prog
java prog
java prog
resolution for prog
Need of ORM
Need of ORM  Why do you need ORM tools like hibernate
need of code
need of code  howto convert greyscale image to binary image in java
need coding
need coding  sir i need code for simple bank application in jsp please send it   sir i need the coding for simple bank application in jsp.   Please visit the following link: Jsp Bank Application
Need Suggistion
Need Suggistion  how to call a callable statement in our jSp page using Struts environment
urgent need
urgent need   Input a line. Count the number of words that start with a capital letter
prog. using radio buttons for simple calculator
prog. using radio buttons for simple calculator  import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class Calculator extends JFrame { private final Font BIGGER_FONT = new Font
prog. using radio buttons for simple calculator
prog. using radio buttons for simple calculator  import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.event.*; class Calculator extends JFrame { private final Font BIGGER_FONT = new Font
need to Program
need to Program   Can any one help me on below How to insert more then one records in EXCEL Sheet using JSP
Need Project
Need Project  How to develop School management project by using Struts Framework? Please give me suggestion and sample examples for my project
need query
need query  hi sir , i am beginner to sql.i need a query so that it can be helpful to my project. i have four tables each containing different fruits with different amounts. i need a query in such a way that when i say some
need
need
need project
need project  hi im new on this site so dnt knw actual procedure . but i need a project on banking system in java with sql database. which should... is good plz add it i need project till Saturday i.e 10th march 2012 plzzzz
need answer
need answer  Given a phone number, as a string, generate the lettercombinations that are possible based on the telephone keypad's number/letter relationship (ie, 1 is related to no letters, 2 is related to 'a' 'b' 'c', 3
Need help
Need help  Hello... I need some help I have a method which contains 1 string value and i wnat when this method get called den that string value should b assigned as array name.. for example.. i have a method name() which
Need help
Need help  Hello... I need some help I have a method which contains 1 string value and i wnat when this method get called den that string value should b assigned as array name.. for example.. i have a method name() which
Need of JUnit
Need of JUnit  Hi sir, What makes JUnit better than other testing tools for Java Unit testing?   Hi friend.. It is better to know.... There's no need to manually comb through a report of test results.ADS_TO_REPLACE_2 4
Need help
Need help  Dear sir, I have a problem. How to write JSP coding, if a user select a value from drop down list for example department, the another drop down list should show the list of name in the department that chosen before
need code
need code  Create Vehicle having following attributes: Vehicle No., Model, Manufacturer and Color. Create truck which has the following additional attributes:loading capacity( 100 tons?).Add a behavior to change the color
need code
need code  Create Vehicle having following attributes: Vehicle No., Model, Manufacturer and Color. Create truck which has the following additional attributes:loading capacity( 100 tons?).Add a behavior to change the color
need code
need code  Create Vehicle having following attributes: Vehicle No., Model, Manufacturer and Color. Create truck which has the following additional attributes:loading capacity( 100 tons?).Add a behavior to change the color
Need help with this!
Need help with this!  Can anyone please help me with this? It's suppose to write to a file student information: student name, student Id, test scores... to effectivly end the loop with out the need to break it. for(i=(0); i <

Ads