Skip to content

Java1-梁笑1407094107 #34

@android-LXZ

Description

@android-LXZ

1.删羊

    int n=2;
    int lengh=sheepList.size();
    for(int i=lengh-1;i>lengh-n-1;i--)
    {
        sheepList.remove(i);
    }

    Iterator it=sheepList.iterator();
    while(it.hasNext())
    {
        sheep sp=(sheep)it.next();
        if(sp.getName()=="慢羊羊")
        sheepList.remove(sp);
    }

    int p=2;
    for(int i=0;i<p;i++)
    {
        sheepList.remove(0);
    }

2、自动写文件

 for(int i=0;i<9;i++){
                file=new File(manyfile,"helloworld"+i+".txt");
                OutputStream out=null;
                try {
                    out=new FileOutputStream(file);
                    String s="我真"+i;
                    try {
                        out.write(s.getBytes());
                    } catch (IOException e) {
                // TODO Auto-generated catch block
                        e.printStackTrace();
                    }
                } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                    e.printStackTrace();
                }
        } 

3、线程

public static void main(String[] arge){
    ThreadExtend th=new ThreadExtend("1--");
    ThreadExtend th1=new ThreadExtend("2--");
    ThreadExtend th2=new ThreadExtend("3--");
    th.start();
    th.start();
    th1.start();
    th2.start();
    Thread th3=new Thread(new ThreadImpl("1--"));
    Thread th4=new Thread(new ThreadImpl("2--"));
    Thread th5=new Thread(new ThreadImpl("3--"));
    th3.start();
    th3.start();
    th4.start();
    th5.start();
    }
}

class ThreadImpl implements Runnable{
    private String name;
    public ThreadImpl(String name){
        this.name=name;
    }
    public ThreadImpl(){

    }

public void run() {
    // TODO Auto-generated method stub
    for(int i=0;i<100;i++){
        System.out.println("i am"+this.getName()+i);
        }   
    }
private String getName() {
    // TODO Auto-generated method stub
    return name;
}

}

class ThreadExtend extends Thread{
    public ThreadExtend(String name){
        super(name);
    }
    public ThreadExtend(){
        super();
    }
    public void run() {
        // TODO Auto-generated method stub
        for(int i=0;i<100;i++){
            System.out.println("i am"+this.getName()+i);
        }
    }

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions