0% found this document useful (0 votes)
3 views2 pages

Java ArrayList String Operations Guide

The document outlines a Java program that performs various string operations using an ArrayList, including appending, inserting, searching, and listing strings that start with a given letter. It introduces Java Collections and provides a complete code implementation for these functionalities. The program is designed for educational purposes in an OOP with Java lab course.

Uploaded by

quetiepie7
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
3 views2 pages

Java ArrayList String Operations Guide

The document outlines a Java program that performs various string operations using an ArrayList, including appending, inserting, searching, and listing strings that start with a given letter. It introduces Java Collections and provides a complete code implementation for these functionalities. The program is designed for educational purposes in an OOP with Java lab course.

Uploaded by

quetiepie7
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

OOP with Java Lab /21CSL35

PROGRAM :9

9. Write a program to perform string operations using ArrayList. Write functions for the
following a. Append - add at end b. Insert – add at particular index c. Search d. List all string
starts with given letter.

Aim: Introduce java Collections.

import [Link].*;
public class ArrayL
{
ArrayList<String> list=new ArrayList<String>(); //Creating arraylist
public void arraydisplay()
{
[Link]("CSE");//Adding object in arraylist
[Link]("ISE");
[Link]("ME");
[Link]("ArrayList element are");
[Link](list);
[Link]("");
}
public void appendatend()
{
[Link]("Enter the element to append at end");
Scanner scob1=new Scanner([Link]);
String ele=[Link]();
[Link](ele);
[Link](list);
[Link]("");
}
public void insertatpos()
{
[Link]("Enter the position and element to insert");
Scanner scob1=new Scanner([Link]);
int posind=[Link]();
String ele=[Link]();
[Link](posind,ele);
[Link](list);
[Link]("");
}
public void searchele()
{
[Link]("Enter the Array element to search");
Scanner scobj=new Scanner([Link]);
String arele=[Link]();
int in=[Link](arele);
if(in==-1)
{
[Link]("Element not found");
}

Prof. Imran Ulla Khan, Dept. of CSE,SKIT 2022-23


OOP with Java Lab /21CSL35

else
{
[Link]("Element found at "+in);
}
}
void print()
{
Scanner nip=new Scanner([Link]);
[Link]("Enter the starting charecter to print strings");
char inputc=[Link]().charAt(0);
String strc=[Link](inputc);
[Link]("String starting with character "+strc);
for(int i=0;i<[Link]();i++)
{
if([Link](i).startsWith(strc))
{
[Link]([Link](i));
}
}
}
public static void main(String args[])
{
ArrayL obj=new ArrayL();
[Link]();
[Link]();
[Link]();
[Link]();
[Link]();
}
}

OUTPUT:

Prof. Imran Ulla Khan, Dept. of CSE,SKIT 2022-23

You might also like