如何在Java中使用集合?

如何在Java中使用集合?,java,geotools,Java,Geotools,我尝试创建一个项目,使用GDAL/OGR将.mif/.tab文件中的数据写入数据库。我有: SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(dbFeatureType); SimpleFeatureCollection collection = FeatureCollections.newCollection(); while (mifReader.hasNext()){ in = (SimpleFea

我尝试创建一个项目,使用GDAL/OGR将.mif/.tab文件中的数据写入数据库。我有:

SimpleFeatureBuilder featureBuilder = new SimpleFeatureBuilder(dbFeatureType);
SimpleFeatureCollection collection = FeatureCollections.newCollection();
while (mifReader.hasNext()){      
  in = (SimpleFeatureImpl) mifReader.next();
  SimpleFeature dbFeature = featureBuilder.buildFeature(null);
  for(AttributeDescriptor ad : adList){
    String name = ad.getLocalName();
    Object attrValue;
    attrValue = in.getAttribute(name);
    if(attrValue instanceof String){
      String string3 = new String((attrValue.toString()).getBytes("ISO-8859-1"), "cp1251");
      if(name.trim().equalsIgnoreCase(kadname.trim())){
        dbFeature.setAttribute("kadnum", string3);
      }
    }
    if (attrValue instanceof Geometry){
        idn++;
        com.vividsolutions.jts.geom.Geometry geom = (Geometry) in.getAttribute(name);
        dbFeature.setAttribute("id", idn);
        System.out.println("after insrt="+idn);
        dbFeature.setAttribute("deleted", deleted);
        dbFeature.setAttribute("the_geom", geom);
        dbFeature.setAttribute("status_id", status_id);

    }
    collection.add(dbFeature);
    }
}
它的简单数据来自.mid文件:

__id_|___kadnum_____

  3,"66:2:00:88 951"
  4,"66:2:00:88 952"
  5,"66:2:00:88 954"
在db中,我得到:

我的数据是2-4行。您可以看到,我获取了增量变量
idn
,并将其放在属性
id
中。从.mid中获取一个
kadnum
,并将其放入属性
kadnum

这很好,但在bd中,我得到的行顺序错误。我的意思是,属性为kadnum=66:2:00:88 951的元素将位于db的第二行,但它位于第四行。
这意味着我要将收藏中物品的顺序改为相反的顺序。这是正确的解决方案吗?如何做到这一点?或者格达尔可以自己做

更新

我有:

 SimplePropertyImpl in =(SimpleFeatureImpl) mifReader.next();
我尝试:

in.getProperty("id").getName() ;

我没有一个属性名,我有一个字符串。我做错了什么?

是否要根据
id
对数据库行进行排序

select * from <yourtable> order by id asc;
会让你从正确的方向开始


值得一提的是,

数据库通常不保证按特定顺序存储行。如果希望以特定顺序从数据库中获取行,请在SQL查询中使用
orderby
子句。您好,我想对集合进行排序。但是我找不到如何使用sortBy.in这一行“@Override getPropertyName(){return“id”}`错误
类型不匹配:无法从字符串转换为PropertyName
我写了“…开始…”,您应该自己做一些工作:-)方法sortBy
类型sortBy已弃用
。这表明您需要编写自己的PropertyName实现来告诉排序算法您要对哪个属性进行排序。
collection.sort( new SortBy() 
                 { 
                     @Override PropertyName getPropertyName() { return YourPropertyNameImpl( "id" ); } 
                     @Override SortOrder getSortOrder() { return SortOrder.ASCENDING; }
                 }