We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
方法1: for (int i = 1; i <=sheepList.size(); i++) { sheepList.remove(2); } 方法2: for(int i=sheepList.size()-1;i>1;i--){ sheepList.remove(i); } 方法3: System.out.println(sheepList.subList(0, 2)); for (int i = 0; i < sheepList.size(); i++) { System.out.println(sheepList.get(i)); } 方法4: Iterator it=sheepList.iterator(); while(it.hasNext()){ Sheep sheepList1=(Sheep)it.next(); if(sheepList1.getName()=="慢羊羊"||sheepList1.getName()=="沸羊羊" ||sheepList1.getName()=="懒羊羊"){ it.remove(); } } 方法5: int count=0; int len=sheepList.size(); Iterator it=sheepList.iterator(); while(it.hasNext()){ if(count >= len - 3){ Object ed=it.next(); it.remove(); } else{ it.next(); count++; } }
for(int i=0;i<10;i++){ File file3=new File(manyfile,"helloworld"+i+".txt"); file=new File(manyfile,"helloworld"+i+".txt"); OutputStream os=null; try { os=new FileOutputStream(file3); String s="我真"+i; try { os.write(s.getBytes()); } catch (IOException e) { e.printStackTrace(); } } catch (Exception e) { e.printStackTrace(); }finally{ try{ os.close(); }catch(IOException e){ e.printStackTrace(); } } }
public class FirstThread extends Thread { private int i; public void run(){ for(i=0;i<5;i++){ System.out.println(getName()+" "+i); } } public static void main(String[] args) { for(int i=0;i<5;i++){ System.out.println(Thread.currentThread().getName()+""+i); if(i==2){ new FirstThread().start(); new FirstThread().start(); } } } } public class SecondThread implements Runnable { private int i; public void run() { for(i=0;i<5;i++){ System.out.println(Thread.currentThread().getName()+""+i); if(i==2){ SecondThread st=new SecondThread(); new Thread(st,"新线程1").start(); new Thread(st,"新线程2").start(); } } } }
Runnable和Thread的区别: 1,通过继承Thread类来创建线程,通过实现接口Runnable来创建线程类,一个类只能继承一个父 类,但可以实现多个接口,因此通过实现接口Runnable可以避免继承的局限性。 2,线程对象的创建:直接创建Thread子类即可代表线程对象;创建的Runable对象只能作为线程对象的target,多个线程可以共享同一个target,因此,实现接口Runnable适合于资源共享。 3,当线程类实现Runnable接口时,只能用Thread.currentThread()方法
The text was updated successfully, but these errors were encountered:
No branches or pull requests
1. 删羊
2. 将我真+i写入文件
3. Runnable和Thread的区别
Runnable和Thread的区别:
1,通过继承Thread类来创建线程,通过实现接口Runnable来创建线程类,一个类只能继承一个父 类,但可以实现多个接口,因此通过实现接口Runnable可以避免继承的局限性。
2,线程对象的创建:直接创建Thread子类即可代表线程对象;创建的Runable对象只能作为线程对象的target,多个线程可以共享同一个target,因此,实现接口Runnable适合于资源共享。
3,当线程类实现Runnable接口时,只能用Thread.currentThread()方法
The text was updated successfully, but these errors were encountered: