Main.java Source code

Java tutorial

Introduction

Here is the source code for Main.java

Source

import java.util.SortedSet;
import java.util.StringTokenizer;
import java.util.TreeSet;

public class Main {
    public static void main(String[] args) {
        String one = "1 2 3 4 5 6";
        String two = " 3 2 1 5 6 4 ";
        Main sc = new Main();
        System.out.println(sc.compare(one, two));
    }

    private boolean compare(String one, String two) {
        SortedSet<Integer> setOne = getSet(one);
        SortedSet<Integer> setTwo = getSet(two);
        return setOne.equals(setTwo);
    }

    private SortedSet<Integer> getSet(String str) {
        SortedSet<Integer> result = new TreeSet<Integer>();
        StringTokenizer st = new StringTokenizer(str, " ");
        while (st.hasMoreTokens()) {
            result.add(Integer.valueOf(st.nextToken()));
        }
        return result;
    }
}