<pre name = "code"> <pre name = "code"> arrays.aslist ()
배열을 목록 개체로 변환합니다. 이 메소드는 arraylist 유형의 객체를 반환합니다. 이 ArrayList 클래스는 java.util.arraylist 클래스가 아니라 배열 클래스의 정적 내부 클래스입니다! 이 객체를 사용하여 목록을 추가, 삭제 및 업데이트하는 경우 지원 UnsupportePerationException을보고합니다.
<pre name = "code"> 자신을 테스트하십시오 : <span> </span> // arraylist <Span> </span> 목록 = 새 ArrayList (); <Span> </span> list.add ( "yz_b_insert"); <pan> </span> list.add ( "yz_b_del"); <span> </span> list.add ( "yz_b_update"); <pan> </span> 목록 .add ( "yz_b_see"); <span> </span> system.out.println (list.contains ( "yz_b_update")+"=="+list); <span> </span> // arrays.aslist () <span> </span> string dd = "yz_b_insert, yz_b_del, yz_b_update, yz_b_see"; <span> </span> list2 = arrays.aslist (dd); <span> </span> system.out.println (list2.contains ( "yz_b_update") @@ "+list2);
출력 결과 :
<pre name = "code"> arraylist : true == [yz_b_insert, yz_b_del, yz_b_update, yzb_see] <pre name = "code"> arrays.aslist () : false @@@@ [yz_b_insert, yz_b_del, yz_b_update, yz_b_see]
<pre name = "code">를 사용하여 컬렉션에 특정 문자열이 있는지 확인하기 위해 <pre name = "code"> arraylist 변환을 사용할 수 없습니다.
나는 그것을 테스트 할 수 없으며, 누군가가 나에게 조언을 줄 수 있다면 조언을 줄 수 있습니다.
다음은 온라인에서 찾은 리소스입니다
<span style = "color : rgb (102, 102, 102); font-family : tahoma;"> 왜 arrays에 의해 생성 된 목록이 추가되거나 삭제되지 않으면, 그렇지 않으면 supportedOperationException이 생성되면 설명을 얻을 수 있습니다. </span> <br style = "색상 : rgb (102, 102, 102); 글꼴 주식 : Tahoma;" /> <br style = "색상 : rgb (102, 102, 102); 글꼴-가족 : Tahoma;" /> <span style = "color : rgb (102, 102, 102); font-family : tahoma;"> 가변 길이 또는 데이터를 목록으로 변환하려면이 목록이 추가 또는 제거를 수행 할 수 있기를 바랍니다. 그러면 어떻게해야합니까? </span> <br style = "색상 : rgb (102, 102, 102); 글꼴 주식 : Tahoma;" /> <br style = "색상 : rgb (102, 102, 102); 글꼴-가족 : Tahoma;" /> <span style = "color : rgb (102, 102, 102); font-family : tahoma;"> 우리는 java.util.arraylist를 직접 사용하는 유사한 메소드를 작성할 수 있습니다. </span> <br style = "색상 : rgb (102, 102, 102); 글꼴 주식 : Tahoma;" /> <br style = "색상 : rgb (102, 102, 102); 글꼴-가족 : Tahoma;" /> <span style = "color : rgb (102, 102, 102); 글꼴-가족 : Tahoma;"> 比如 : </span> <br style = "color : rgb (102, 102, 102); font-family : tahoma;" /> <pre name = "code"style = "color : rgb (102, 102, 102); 배경색 : rgb (255, 255, 255);"> import java.util.arraylist; import java.util.collections; import java.util.list; public class <t> list <t> aslist (t> aslist <t> aslist <t> list <t> list <t> list <t> ArrayList <t> (); collections.Addall (list, a); 반환 목록;}}
테스트 코드는 다음과 같습니다.
import java.util.arraylist; import java.util.arrays; import java.util.list; public class test {@suppresswarnings (@suppresswarnings (@suppresswarnings)) public static void main (string [] args) {list <string> standes = arrays.aslist ( "larry", "moe", "print"; print "); SeasonsList = arrays.asList (retrievesSissList ()); print (seasonsList);/ * * ASLIST 메소드를 직접 구현하여 추가 및 삭제할 수 있습니다. */list <string> list = myArrays.asList ( "larry", "moe", "curly"); list.add ( "hello");} private static <t> void print (list <t> list) {system.out.println (list);} private static list <string> retrieveslist (list <string <string> news = new). ArrayList <string> (); SeasonsList.Add ( "Spring"); SeasonsList.Add ( "Summer"); SeasonsList.Add ( "Autumn"); SeasonsList.Add ( "Winter"); Return SeasonsList;}}출력 결과 :
[Larry, Moe, Curly]
[[봄, 여름, 가을, 겨울]]]
[Larry, Moe, Curly, Hello]
위는 Array.aslist ()와 Arraylist 유형의 차이점에 대한 간단한 논의입니다. 모두가 wulin.com을 지원하기를 바랍니다