Java I';我试图在不使用预制类的情况下按ABC顺序对字符串数组列表进行排序

Java I';我试图在不使用预制类的情况下按ABC顺序对字符串数组列表进行排序,java,arrays,arraylist,Java,Arrays,Arraylist,我无法按ABC顺序排序数组列表。这就是我到目前为止所拥有的,关于如何实现它有什么想法吗?我的输出是切换一些单词,但不是将整个数组列表按ABC顺序排列。我迷路了,你可以从我最后的循环中看出=[ import java.util.ArrayList; import java.util.Scanner; public class ArrayListLab { public static void main (String [] args) { Scanner scan = n

我无法按ABC顺序排序数组列表。这就是我到目前为止所拥有的,关于如何实现它有什么想法吗?我的输出是切换一些单词,但不是将整个数组列表按ABC顺序排列。我迷路了,你可以从我最后的循环中看出=[

import java.util.ArrayList;
import java.util.Scanner;
public class ArrayListLab
{
   public static void main (String [] args)
   {
       Scanner scan = new Scanner (System.in);
       ArrayList <String> words = new ArrayList <String> ();
       for (int x = 0; x < 10; x++)
       {
           System.out.println("Pick a word, any word!");
           words.add(scan.nextLine());
        }
       for (int x = 0; x < 9; x++)
       {
         words.get(x).compareTo(words.get(x+1));
         if (words.get(x).compareTo(words.get(x+1))>0)
         {
            String temp = words.get(x+1);
            words.set((x+1),words.get(x));
            words.set(x, temp);
         }
        else
           if (words.get(x).compareTo(words.get(x+1))<0)
           {
              words.get(x);  
           }
           else
              if(words.get(x).compareTo(words.get(x+1))==0)
              {
                  words.get(x);
              }

    }
    System.out.println(words);
}
}
import java.util.ArrayList;
导入java.util.Scanner;
公共类ArrayListLab
{
公共静态void main(字符串[]args)
{
扫描仪扫描=新扫描仪(System.in);
ArrayList words=新的ArrayList();
对于(int x=0;x<10;x++)
{
System.out.println(“选择一个单词,任何单词!”);
words.add(scan.nextLine());
}
对于(int x=0;x<9;x++)
{
words.get(x).compareTo(words.get(x+1));
如果(words.get(x).compareTo(words.get(x+1))>0
{
String temp=words.get(x+1);
words.set((x+1),words.get(x));
单词。设置(x,temp);
}
其他的

if(words.get(x).compareTo(words.get(x+1))您试图实现哪种排序算法?premade类是什么意思?Arraylist是“premade”的,如果您使用的是字符串类型.Collections.sort(list),为什么不使用集合的sort()方法呢?此外,在单个for循环中对列表进行排序也是不可能的