spark flatmap - scala到java代码

时间:2016-08-15 07:25:03

标签: java scala apache-spark

我一直在练火花。我对scala不是很熟悉,想尝试java代码。对于map和flatmap的以下基本操作,我如何在java中编写以下代码

sc.parallelize(List(1,2,3)).flatMap(x=>List(x,x,x)).collect
sc.parallelize(List(1,2,3)).map(x=>List(x,x,x)).collect

1 个答案:

答案 0 :(得分:-1)

它基本相同:

@Override
    public boolean onNavigationItemSelected(MenuItem item) {
        // Handle navigation view item clicks here.
        int id = item.getItemId();
        Fragment newFragment;
        android.support.v4.app.FragmentTransaction transaction = getSupportFragmentManager().beginTransaction();

        if (id == R.id.nav_gradesheet) {
            // Handle the camera action
            newFragment = new GradeSheet();
            transaction.replace(R.id.yeah2, newFragment);
            transaction.addToBackStack(null);
            transaction.commit();

        } else if (id == R.id.nav_summarygradesheet) {

        }

        DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        drawer.closeDrawer(GravityCompat.START);
        return true;
    }

其中sc.parallelize(Arrays.asList(1,2,3)).flatMap(x->Arrays.asList(x,x,x).iterator()).collect(); sc.parallelize(Arrays.asList(1,2,3)).map(x->Arrays.asList(x,x,x)).collect(); JavaSparkContext(假设您使用Java 8和Spark 2.0.0)。