Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public class Mylist{
- String [] list;
- public Mylist(){
- String []list;
- }
- public Mylist(String s){
- list=new String[1];
- list[0]=s;
- }
- public Mylist(String []s){
- list=s;
- }
- public int Length(){
- return list.length;
- }
- public String First(){
- return this.list[0];
- }
- public String[] Rest(){
- list[0]="";
- return list;
- }
- public void Insert(String n, int j){
- list[j]=n;
- }
- public void Delete(String e){
- for(int k=0;k<list.length;k++){
- if(list[k]==e){
- list[k]="";
- }
- }
- }
- public boolean isEmpty(){
- if(list != null){
- return false;
- }
- else return true;
- }
- public boolean subList(String[]f){
- int l=0;
- int m=0;
- while (m<list.length && l<f.length){
- if(f[l].equals(list[m])){
- l++;
- }
- m++;
- }
- if(l==f.length){
- return true;
- }
- else return false;
- }
- //now for testing the code
- public static void main (String[] args) {
- Mylist l1=new Mylist();
- Mylist l2=new Mylist("Ali");
- String [] trail={"ali","ahmad","mohamed","mostafa","ali","hetham","said","ali"};
- Mylist l3=new Mylist(trail);
- System.out.println("the length of trail is "+l3.Length());
- System.out.println("the first name in trail is "+l3.First());
- System.out.print("while the rest are " );
- String[]reast=l3.Rest();
- for(int x=0;x<reast.length;x++){
- System.out.print(reast[x]+ " ");
- }
- System.out.println("the first and only name in list 2 is "+ l2.First());
- l2.Insert("shafee2 :)",0);
- System.out.println("which after changing became "+l2.First());
- l3.Delete("ali");
- System.out.print("list 3 after purifying it from ali is "+l3.First());
- String[]loot=l3.Rest();
- for(int y=0;y<loot.length;y++){
- System.out.print(loot[y]+ " ");
- }
- System.out.println("whoever said list 1 is empty was "+l1.isEmpty());
- String []finale={"ahmad","mohamed","said"};
- System.out.println("the final question is if given list is substring of L3, the answer is " +l3.subList(finale));
- }
- //done...
- }
Add Comment
Please, Sign In to add comment