简体   繁体   English

如何快速找到一种已经实施的方法?

[英]How to quickly find a method that has already been implemented?

I am a new java programmer.At the beginning,i write a method convert Integer List to int[] in my project 我是一名新的Java程序员。一开始,我在我的项目中编写了一种将Integer List转换为int []的方法

 public int[] convertToArray(List<Integer> list) { int[] array = new int[list.size()]; for (int i = 0; i < list.size(); i++) { array[i] = list.get(i); } return array; } 
Later,i found that Guava Ints.toArray has been already implemented this logic,it use generics and far better than my write.Guava or Apache commons has a lot of API and i can't remember all of it. 后来,我发现Guava Ints.toArray已经实现了这种逻辑,它使用了泛型并且比我的编写要好得多。Guava或Apache Commons有很多API,我不记得所有这些。 So, i wondering is there a way that when i want to write some logic , it can tell me that "Hey , the Guava or Apache commons XXX Class XXX method has already implement this logic ,just use it ,Stop Trying to Reinvent the Wheel"? 因此,我想知道是否有一种方法可以在我要编写一些逻辑时告诉我:“嘿,Guava或Apache Commons XXX类XXX方法已经实现了此逻辑,只需使用它,请停止尝试重新发明轮子。 “?

Been there many times. 去过那里很多次了。 Have spent hours to write a piece of logic only to find it has been already implemented through a library. 花了数小时编写一条逻辑,只是发现它已经通过库实现了。

One thing you could do is to google what you are trying to achieve if you are about to write any utility function like the one in your question. 您可以做的一件事是,如果您要编写任何实用程序函数(如您所问的那个函数),请用谷歌搜索要达到的目标。 Most likely you would find a library or two. 您很可能会找到一两个图书馆。

Another way would be to read the documentation of famous libraries like Apache Commons, Guava etc. 另一种方法是阅读著名库(如Apache Commons,Guava等)的文档。

There aren't any easier ways. 没有更简单的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在已经构造的数组中找到平均数 - How to find the average number in an array that has already been constructed 如何确定字符串是否已被 URL 编码? - How to find out if string has already been URL encoded? Appium“ HasClipboard()”的“方法尚未实现”异常 - “Method has not yet been implemented” exception for appium `HasClipboard()` 变量已经在我的方法中定义了,还是已经定义了? - Variable has already been defined in my method, or has it? 如何判断列表是否已经加载? - How to tell if a list has already been loaded? 如何反转已经反转的字符串? - How to reverse a string that has already been reversed? 该算法是否已正确实施? - Has this algorithm been implemented properly? 如何在Eclipse中查找抽象方法的实现位置? - How to find where an abstract method is implemented in Eclipse? 有条件的方法比以往更令人满意 - Conditional in a method that way more than often has already been satisified 仍然出现错误:即使在实现了方法“ OnFocusChangeListener”中的“实现抽象方法“ onFocusChange(View,boolean)” - still getting error: 'implement abstract method 'onFocusChange(View, boolean)' in 'OnFocusChangeListener' even when the method has been implemented
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM