简体   繁体   中英

Pointer, Vector and Iterator in Java

I've got some C++ codes about vector, pointer and iterator. But I'm not sure about what the codes do. I guess, it does iteration using iterator to get or check every single vector value, then when value inner vector still doesn't end or has next, it will create a vector name v that is filled with pointer from d. Is it right? Now, I want to convert that code into java code, especially Java Android. So far, I have converted until WHILE section. I don't have any idea for converting section create new vector with pointer. Could you help me? Thank you so much.

C++ Code :

size_t count = contours_hull[i].size();
if( count < 300 )
   continue;
vector<Vec4i>::iterator d =defects[i].begin();
while( d!=defects[i].end() ) {
    Vec4i& v=(*d); //this line, i can't convert.
//another code
}

Java Code that I did it :

for(int i = 0; i < contours_hull.size(); i++) // I added this line, because in java "continue" cannot use in outside loop, so i make loop here.
{
    int count = contours_hull.size();
    if (count < 300) continue;
    List<MatOfInt4> defect = new ArrayList<MatOfInt4>();
    Iterator d =  defect.iterator();
    while (d.hasNext)
    {
        //the line "Vec4i& v=(*d);" that i can't convert
    }
}

Is it right to convert them like that? And what should i write for the code that hasn't converted? Anyone, Could you help me ???

That's just a deference operator. It's equivalent to ListIterator.next() in your Java code. Considering C++ code stores it as reference, it's basically identical.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM