我需要帮助来编写一个java接口 [英] I need help to write a java interface
本文介绍了我需要帮助来编写一个java接口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要帮助来编写一个名为Reversible的Java接口,它有一个方法public void reverse(),它可以反转列表中的元素。
< b>我尝试了什么:
我试过了
I need help to Write a Java interface called Reversible which has a single method public void reverse(), where it reverses the elements in a list.
What I have tried:
I have tried
import java.util.ArrayList;
import java.util.Collections;
public class ReverseListOrder {
public static void main(String[] args) {
ArrayList arrayList = new ArrayList();
arrayList.add("0");
arrayList.add("1");
arrayList.add("2");
arrayList.add("3");
arrayList.add("4");
System.out.println("ArrayList elements : " + arrayList);
Collections.reverse(arrayList);
System.out.println("ArrayList elements after reversing order : " + arrayList);
}
}
但我不认为这是一个'界面'。
but i dont think this is an 'interface'.
推荐答案
No, this is a complete application.
参见什么是接口? (Java™教程>学习Java语言>面向对象的编程概念) [ ^ ]。
非常简单:创建一个新的集合,通过倒计时将旧集合的元素带入新的并分配结果。
Very easy: create a new collection, take the elements of the old collection via count down into the new and assign the result.
这篇关于我需要帮助来编写一个java接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文